neo4j 8.0.0.alpha.2 → 8.0.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74a57c27a28cfa8eda0a7a71413d428e40d2802a
4
- data.tar.gz: 51e4a2ef533ae4fbe85daa56365f8e7244ffa7f3
3
+ metadata.gz: bd2973cc137423aab039e28ea9e4408447277665
4
+ data.tar.gz: 3d62800551e950fbdaadf39c6893f88371247d56
5
5
  SHA512:
6
- metadata.gz: 8f0bdf1994b8871a6c5f333661fa6f77d46f3cb7a0c811b1612580509d8829979dac47461a5978758a732fd04fa940489ba53da41bdf78b8d14303545a8c94f7
7
- data.tar.gz: 68279d917be513365d828850cd5967c350d574fe9d0bbf0d4b7aff6d7fb767e2720c0a911e9076a7bd89706401e775a6545801a0ca632fd17dc06aa51b51a102
6
+ metadata.gz: ab42853f116ac28744c2d1fba3e7753a4361c677269615e4ee54b5c828e8106220106ba951bffec8a0b13d27962c046f837c0ee68fbb097b3044ec2b07cdcf5b
7
+ data.tar.gz: ae0c2386e659388839510a7c9f573a922c18772455726b3ce53218f9596850b68f5fe89f183d60447a7281e0daa1b018bfbf9be6db24cf18ca7f33d082f68ff0
@@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file.
3
3
  This file should follow the standards specified on [http://keepachangelog.com/]
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [Unreleased]
7
+
8
+ ### Added
9
+
10
+ - A `Neo4j::Migrations.maintain_test_schema!` method, to keep the test database up to date with schema changes. (see #1277)
11
+ - A `Neo4j::Migrations.check_for_pending_migrations!` method, that fails when there are pending migration. In Rails, it's executed automatically on startup. (see #1277)
12
+ - Support for [`ForbiddenAttributesProtection` API](http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html) from ActiveRecord. (thanks ProGM, see #1245)
13
+
14
+ ### Changed
15
+
16
+ - `ActiveNode#destroy` and `ActiveRel#destroy` now return the object in question rather than `true` to be compatible with `ActiveRecord` (see #1254)
17
+
18
+ ### Fixed
19
+
20
+ - Bugs with using `neo_id` as `ActiveNode` `id_property` (thanks klobuczek / see #1274)
21
+
6
22
  ## [8.0.0.alpha.2] 2016-08-05
7
23
 
8
24
  ### Changed
@@ -52,6 +68,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
52
68
 
53
69
  - Made some memory optimizations (thanks ProGM / see #1221)
54
70
 
71
+ ## [7.2.0] - 08-23-2016
72
+
73
+ ### Added
74
+
75
+ - Backporting #1245 to 7.x versions. It implements the [`ForbiddenAttributesProtection` API](http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html) from ActiveRecord.
76
+
77
+ ## [7.1.3] - 08-18-2016
78
+
79
+ ### Changed
80
+
81
+ - Default value for `enum` is `nil` instead of the first value. This is a **BREAKING** change but is being released as a patch because the original behavior was considered a bug. See [this pull request](https://github.com/neo4jrb/neo4j/pull/1270) (thanks to ProGM and andyweiss1982)
82
+
83
+ ## [7.1.2] - 08-01-2016
84
+
85
+ ### Fixed
86
+
87
+ - Fixed issue where the label wrapping cache would get stuck
88
+
55
89
  ## [7.1.1] - 07-22-2016
56
90
 
57
91
  ### Fixed
@@ -65,6 +99,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
65
99
  - Gemspec dependency requirements were modified where ActiveModel, ActiveSupport, and Railties are concerned. The gem now requires >= 4.0, < 5.1.
66
100
  - `ActiveModel::Serializers::Xml` is only included if supported if available.
67
101
 
102
+ ## [7.0.15] - 08-18-2016
103
+
104
+ ### Changed
105
+
106
+ - Default value for `enum` is `nil` instead of the first value. This is a **BREAKING** change but is being released as a patch because the original behavior was considered a bug. See [this pull request](https://github.com/neo4jrb/neo4j/pull/1270) (thanks to ProGM and andyweiss1982)
107
+
68
108
  ## [7.0.14] - 07-10-2016
69
109
 
70
110
  ### Fixed
@@ -82,7 +122,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
82
122
  ### Fixed
83
123
 
84
124
  - Fix dipendence from JSON when using outside of rails (thanks ProGM)
85
- >>>>>>> 7.1.x
86
125
 
87
126
  ## [7.0.10] - 06-07-2016
88
127
 
data/Gemfile CHANGED
@@ -19,23 +19,25 @@ end
19
19
  gem 'listen', '< 3.1'
20
20
 
21
21
  if RUBY_VERSION.to_f < 2.2
22
- gem 'activemodel', '~> 4'
23
- gem 'activesupport', '~> 4'
24
- gem 'railties', '~> 4'
22
+ gem 'activemodel', '~> 4.2'
23
+ gem 'activesupport', '~> 4.2'
24
+ gem 'railties', '~> 4.2'
25
25
  end
26
26
 
27
- gem 'tins', '< 1.7' if RUBY_VERSION.to_f < 2.0
28
-
29
27
  group 'test' do
30
28
  gem 'coveralls', require: false
31
- gem 'tins', '< 1.7' if RUBY_VERSION.to_f < 2.0
29
+ if RUBY_VERSION.to_f < 2.0
30
+ gem 'tins', '< 1.7'
31
+ gem 'overcommit', '< 0.35.0'
32
+ else
33
+ gem 'overcommit'
34
+ end
32
35
  gem 'codecov', require: false
33
36
  gem 'simplecov', require: false
34
37
  gem 'simplecov-html', require: false
35
38
  gem 'rspec', '~> 3.4'
36
39
  gem 'its'
37
40
  gem 'test-unit'
38
- gem 'overcommit'
39
41
  gem 'colored'
40
42
  gem 'dotenv'
41
43
  gem 'timecop'
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('rake', 'rake')
@@ -45,6 +45,7 @@ require 'neo4j/shared/typecaster'
45
45
  require 'neo4j/shared/initialize'
46
46
  require 'neo4j/shared/query_factory'
47
47
  require 'neo4j/shared/cypher'
48
+ require 'neo4j/shared/permitted_attributes'
48
49
  require 'neo4j/shared'
49
50
 
50
51
  require 'neo4j/active_rel/callbacks'
@@ -61,7 +61,7 @@ module Neo4j
61
61
  end
62
62
 
63
63
  def logger
64
- @logger ||= (Neo4j::Config[:logger] || Logger.new(STDOUT))
64
+ @logger ||= (Neo4j::Config[:logger] || ActiveSupport::Logger.new(STDOUT))
65
65
  end
66
66
  end
67
67
  end
@@ -44,12 +44,13 @@ module Neo4j
44
44
  include Neo4j::ActiveNode::Scope
45
45
  include Neo4j::ActiveNode::Dependent
46
46
  include Neo4j::ActiveNode::Enum
47
+ include Neo4j::Shared::PermittedAttributes
47
48
 
48
49
  def initialize(args = nil)
49
50
  self.class.ensure_id_property_info! # So that we make sure all objects have an id_property
50
51
 
51
- symbol_args = args.is_a?(Hash) ? args.symbolize_keys : args
52
- super(symbol_args)
52
+ args = sanitize_input_parameters(args)
53
+ super(args)
53
54
  end
54
55
 
55
56
  def neo4j_obj
@@ -81,6 +82,8 @@ module Neo4j
81
82
  end
82
83
 
83
84
  def self.inherited(other)
85
+ Neo4j::ActiveNode::Labels.clear_wrapped_models
86
+
84
87
  LOADED_CLASSES << other
85
88
  other.instance_variable_set('@inherited', true)
86
89
  inherit_id_property(other)
@@ -38,10 +38,10 @@ module Neo4j::ActiveNode
38
38
 
39
39
  module TypeMethods
40
40
  def define_id_methods(clazz, name, conf)
41
- validate_conf!(conf)
42
-
43
41
  return if name == :neo_id
44
42
 
43
+ validate_conf!(conf)
44
+
45
45
  if conf[:on]
46
46
  define_custom_method(clazz, name, conf[:on])
47
47
  elsif conf[:auto]
@@ -188,16 +188,16 @@ module Neo4j::ActiveNode
188
188
 
189
189
  def handle_model_schema!
190
190
  id_property_name = @id_property_info[:name]
191
+
192
+ return if id_property_name == :neo_id || @id_property_info[:inherited]
193
+
191
194
  if @id_property_info[:type][:constraint] == false &&
192
- !@id_property_info[:inherited] &&
193
195
  !@id_property_info[:warned_of_constraint]
194
196
  @id_property_info[:warned_of_constraint] = true
195
197
  warn_constraint_option_false!(id_property_name)
196
198
  return
197
199
  end
198
200
 
199
- return if id_property_name == :neo_id || @id_property_info[:inherited]
200
-
201
201
  Neo4j::ModelSchema.add_defined_constraint(self, id_property_name)
202
202
  end
203
203
 
@@ -211,7 +211,7 @@ MSG
211
211
  def id_property_name_type_value
212
212
  name, type, value = Neo4j::Config.to_hash.values_at(*%w(id_property id_property_type id_property_type_value))
213
213
 
214
- if !(name && type && value)
214
+ unless name == :neo_id || (name && type && value)
215
215
  name = :uuid
216
216
  type = :auto
217
217
  value = :uuid
@@ -13,11 +13,7 @@ module Neo4j
13
13
  MODELS_FOR_LABELS_CACHE.clear
14
14
 
15
15
  included do |model|
16
- def self.inherited(model)
17
- add_wrapped_class(model)
18
-
19
- super
20
- end
16
+ Neo4j::ActiveNode::Labels.clear_wrapped_models
21
17
 
22
18
  Neo4j::ActiveNode::Labels.add_wrapped_class(model) unless Neo4j::ActiveNode::Labels._wrapped_classes.include?(model)
23
19
  end
@@ -18,13 +18,14 @@ module Neo4j
18
18
  include Neo4j::ActiveRel::Query
19
19
  include Neo4j::ActiveRel::Types
20
20
  include Neo4j::Shared::Enum
21
+ include Neo4j::Shared::PermittedAttributes
21
22
 
22
23
  class FrozenRelError < Neo4j::Error; end
23
24
 
24
25
  def initialize(from_node = nil, to_node = nil, args = nil)
25
26
  load_nodes(node_or_nil(from_node), node_or_nil(to_node))
26
27
  resolved_args = hash_or_nil(from_node, args)
27
- symbol_args = resolved_args.is_a?(Hash) ? resolved_args.symbolize_keys : resolved_args
28
+ symbol_args = sanitize_input_parameters(resolved_args)
28
29
  super(symbol_args)
29
30
  end
30
31
 
@@ -60,26 +61,7 @@ module Neo4j
60
61
  end
61
62
 
62
63
  def hash_or_nil(node_or_hash, hash_or_nil)
63
- node_or_hash.is_a?(Hash) ? node_or_hash : hash_or_nil
64
- end
65
-
66
- module ClassMethods
67
- [:create, :create!].each do |meth|
68
- define_method(meth) do |from_node_or_args = nil, to_node = nil, args = nil|
69
- return super(from_node_or_args) if from_node_or_args.is_a?(Hash)
70
- args_hash = args || {}
71
- args_with_node!(:from_node, from_node_or_args, args_hash)
72
- args_with_node!(:to_node, to_node, args_hash)
73
- super(args_hash)
74
- end
75
- end
76
-
77
- private
78
-
79
- def args_with_node!(key, node, args)
80
- args[key] = node if node.is_a?(Neo4j::ActiveNode)
81
- args
82
- end
64
+ hash_or_parameter?(node_or_hash) ? node_or_hash : hash_or_nil
83
65
  end
84
66
  end
85
67
  end
@@ -60,26 +60,13 @@ module Neo4j::ActiveRel
60
60
  module ClassMethods
61
61
  # Creates a new relationship between objects
62
62
  # @param [Hash] props the properties the new relationship should have
63
- def create(props = {})
64
- relationship_props = extract_association_attributes!(props) || {}
65
- new(props).tap do |obj|
66
- relationship_props.each do |prop, value|
67
- obj.send("#{prop}=", value)
68
- end
69
- obj.save
70
- end
63
+ def create(*args)
64
+ new(*args).tap(&:save)
71
65
  end
72
66
 
73
67
  # Same as #create, but raises an error if there is a problem during save.
74
68
  def create!(*args)
75
- props = args[0] || {}
76
- relationship_props = extract_association_attributes!(props) || {}
77
- new(props).tap do |obj|
78
- relationship_props.each do |prop, value|
79
- obj.send("#{prop}=", value)
80
- end
81
- obj.save!
82
- end
69
+ new(*args).tap(&:save!)
83
70
  end
84
71
 
85
72
  def create_method
@@ -95,6 +95,10 @@ module Neo4j
95
95
  configuration.to_yaml
96
96
  end
97
97
 
98
+ def fail_on_pending_migrations
99
+ Neo4j::Config[:fail_on_pending_migrations].nil? ? true : Neo4j::Config[:fail_on_pending_migrations]
100
+ end
101
+
98
102
  def include_root_in_json
99
103
  # we use ternary because a simple || will always evaluate true
100
104
  Neo4j::Config[:include_root_in_json].nil? ? true : Neo4j::Config[:include_root_in_json]
@@ -17,6 +17,8 @@ module Neo4j
17
17
  end
18
18
  end
19
19
 
20
+ class DeprecatedSchemaDefinitionError < Error; end
21
+
20
22
  class InvalidPropertyOptionsError < Error; end
21
23
 
22
24
  class InvalidParameterError < Error; end
@@ -25,7 +27,30 @@ module Neo4j
25
27
 
26
28
  class DangerousAttributeError < ScriptError; end
27
29
  class UnknownAttributeError < NoMethodError; end
30
+
28
31
  class MigrationError < Error; end
29
32
  class IrreversibleMigration < MigrationError; end
30
33
  class UnknownMigrationVersionError < MigrationError; end
34
+
35
+ # Inspired/taken from active_record/migration.rb
36
+ class PendingMigrationError < MigrationError
37
+ def initialize
38
+ if rails? && defined?(Rails.env)
39
+ super("Migrations are pending. To resolve this issue, run:\n\n #{command_name} neo4j:migrate RAILS_ENV=#{::Rails.env}")
40
+ else
41
+ super("Migrations are pending. To resolve this issue, run:\n\n #{command_name} neo4j:migrate")
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def command_name
48
+ return 'rake' unless rails?
49
+ Rails.version.to_f >= 5 ? 'bin/rails' : 'bin/rake'
50
+ end
51
+
52
+ def rails?
53
+ defined?(Rails)
54
+ end
55
+ end
31
56
  end
@@ -6,5 +6,14 @@ module Neo4j
6
6
  autoload :Base
7
7
  autoload :Runner
8
8
  autoload :SchemaMigration
9
+
10
+ def self.check_for_pending_migrations!
11
+ runner = Neo4j::Migrations::Runner.new
12
+ fail ::Neo4j::PendingMigrationError if runner.pending_migrations?
13
+ end
14
+
15
+ def self.maintain_test_schema!
16
+ Neo4j::Migrations::Runner.new(silenced: true).all
17
+ end
9
18
  end
10
19
  end
@@ -11,7 +11,8 @@ module Neo4j
11
11
  MIGRATION_RUNNING = {up: 'running'.freeze, down: 'reverting'.freeze}.freeze
12
12
  MIGRATION_DONE = {up: 'migrated'.freeze, down: 'reverted'.freeze}.freeze
13
13
 
14
- def initialize
14
+ def initialize(options = {})
15
+ @silenced = options[:silenced] || !!ENV['MIGRATIONS_SILENCED']
15
16
  SchemaMigration.mapped_label.create_constraint(:migration_id, type: :unique)
16
17
  @schema_migrations = SchemaMigration.all.to_a
17
18
  @up_versions = SortedSet.new(@schema_migrations.map(&:migration_id))
@@ -46,6 +47,10 @@ module Neo4j
46
47
  end
47
48
  end
48
49
 
50
+ def pending_migrations?
51
+ all_migrations.any? { |migration| !up?(migration) }
52
+ end
53
+
49
54
  def status
50
55
  output STATUS_TABLE_FORMAT, *STATUS_TABLE_HEADER
51
56
  output SEPARATOR
@@ -118,7 +123,7 @@ MSG
118
123
  end
119
124
 
120
125
  def output(*string_format)
121
- puts format(*string_format) unless !!ENV['MIGRATIONS_SILENCED']
126
+ puts format(*string_format) unless @silenced
122
127
  end
123
128
 
124
129
  def output_migration_message(message)
@@ -79,22 +79,28 @@ module Neo4j
79
79
  @model_indexes = @model_constraints = nil
80
80
  end
81
81
 
82
+ def legacy_model_schema_informations
83
+ data = {index: [], constraint: []}
84
+ each_schema_element do |type, model, label, property_name|
85
+ data[type] << {label: label, property_name: property_name, model: model}
86
+ end
87
+ data
88
+ end
89
+
82
90
  def validate_model_schema!
83
91
  ensure_model_data_state!
84
92
  messages = {index: [], constraint: []}
85
- [[:constraint, model_constraints], [:index, model_indexes]].each do |type, schema_elements|
86
- schema_elements.map do |model, label, property_name, exists|
87
- if exists
88
- log_warning!(type, model, property_name) if model.id_property_name.to_sym != property_name
89
- else
90
- messages[type] << force_add_message(type, label, property_name)
91
- end
93
+ each_schema_element do |type, model, label, property_name, exists|
94
+ if exists
95
+ log_warning!(type, model, property_name) if model.id_property_name.to_sym != property_name
96
+ else
97
+ messages[type] << force_add_message(type, label, property_name)
92
98
  end
93
99
  end
94
100
 
95
101
  return if messages.values.all?(&:empty?)
96
102
 
97
- fail validation_error_message(messages)
103
+ fail ::Neo4j::DeprecatedSchemaDefinitionError, validation_error_message(messages)
98
104
  end
99
105
 
100
106
  def validation_error_message(messages)
@@ -117,6 +123,16 @@ MSG
117
123
  def log_warning!(index_or_constraint, model, property_name)
118
124
  Neo4j::ActiveBase.logger.warn "WARNING: The #{index_or_constraint} option is no longer supported (Defined on #{model.name} for #{property_name})"
119
125
  end
126
+
127
+ private
128
+
129
+ def each_schema_element
130
+ [[:constraint, model_constraints], [:index, model_indexes]].each do |type, schema_elements|
131
+ schema_elements.each do |args|
132
+ yield(type, *args)
133
+ end
134
+ end
135
+ end
120
136
  end
121
137
  end
122
138
  end
@@ -22,17 +22,10 @@ module Neo4j
22
22
  end
23
23
 
24
24
  # Rescue responses similar to ActiveRecord.
25
- # For rails 3.2 and 4.0
26
- if config.action_dispatch.respond_to?(:rescue_responses)
27
- config.action_dispatch.rescue_responses.merge!(
28
- 'Neo4j::RecordNotFound' => :not_found,
29
- 'Neo4j::ActiveNode::Labels::RecordNotFound' => :not_found
30
- )
31
- else
32
- # For rails 3.0 and 3.1
33
- ActionDispatch::ShowExceptions.rescue_responses['Neo4j::RecordNotFound'] = :not_found
34
- ActionDispatch::ShowExceptions.rescue_responses['Neo4j::ActiveNode::Labels::RecordNotFound'] = :not_found
35
- end
25
+ config.action_dispatch.rescue_responses.merge!(
26
+ 'Neo4j::RecordNotFound' => :not_found,
27
+ 'Neo4j::ActiveNode::Labels::RecordNotFound' => :not_found
28
+ )
36
29
 
37
30
  # Add ActiveModel translations to the I18n load_path
38
31
  initializer 'i18n' do
@@ -61,6 +54,7 @@ module Neo4j
61
54
  session_types = cfg.sessions.map { |session_opts| session_opts[:type] }
62
55
 
63
56
  register_neo4j_cypher_logging(session_types)
57
+ Neo4j::Migrations.check_for_pending_migrations! if Rails.env.development? && Neo4j::Config.fail_on_pending_migrations
64
58
  end
65
59
 
66
60
  TYPE_SUBSCRIBERS = {
@@ -64,8 +64,7 @@ module Neo4j::Shared
64
64
  end
65
65
  end
66
66
 
67
- VALID_OPTIONS_FOR_ENUMS = [:_prefix, :_suffix]
68
- DEFAULT_OPTIONS_FOR_ENUMS = {}
67
+ VALID_OPTIONS_FOR_ENUMS = [:_index, :_prefix, :_suffix, :_default]
69
68
 
70
69
  def split_options_and_parameters(parameters)
71
70
  options = {}
@@ -80,9 +79,16 @@ module Neo4j::Shared
80
79
  [options, new_parameters]
81
80
  end
82
81
 
83
- def define_property(property_name, enum_keys, _options)
84
- property property_name, default: enum_keys.keys.first # .merge(options)
85
- serialize property_name, Neo4j::Shared::TypeConverters::EnumConverter.new(enum_keys)
82
+ def define_property(property_name, enum_keys, options)
83
+ property_options = build_property_options(enum_keys, options)
84
+ property property_name, property_options
85
+ serialize property_name, Neo4j::Shared::TypeConverters::EnumConverter.new(enum_keys, property_options)
86
+ end
87
+
88
+ def build_property_options(_enum_keys, options = {})
89
+ {
90
+ default: options[:_default]
91
+ }
86
92
  end
87
93
 
88
94
  def define_enum_methods(property_name, enum_keys, options)
@@ -0,0 +1,28 @@
1
+ module Neo4j::Shared
2
+ module PermittedAttributes
3
+ extend ActiveSupport::Concern
4
+ include ActiveModel::ForbiddenAttributesProtection
5
+
6
+ def process_attributes(attributes)
7
+ attributes = sanitize_input_parameters(attributes)
8
+ super(attributes)
9
+ end
10
+
11
+ def attributes=(attributes)
12
+ attributes = sanitize_input_parameters(attributes)
13
+ super(attributes)
14
+ end
15
+
16
+ protected
17
+
18
+ # Check if an argument is a string or an ActionController::Parameters
19
+ def hash_or_parameter?(args)
20
+ args.is_a?(Hash) || args.respond_to?(:to_unsafe_h)
21
+ end
22
+
23
+ def sanitize_input_parameters(attributes)
24
+ attributes = sanitize_for_mass_assignment(attributes)
25
+ attributes.respond_to?(:symbolize_keys) ? attributes.symbolize_keys : attributes
26
+ end
27
+ end
28
+ end
@@ -123,6 +123,8 @@ module Neo4j::Shared
123
123
  destroy_query.exec if _persisted_obj
124
124
 
125
125
  @_deleted = true
126
+
127
+ self
126
128
  end
127
129
 
128
130
  def exist?
@@ -264,8 +264,9 @@ module Neo4j::Shared
264
264
  end
265
265
 
266
266
  class EnumConverter
267
- def initialize(enum_keys)
267
+ def initialize(enum_keys, options)
268
268
  @enum_keys = enum_keys
269
+ @options = options
269
270
  end
270
271
 
271
272
  def converted?(value)
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '8.0.0.alpha.2'
2
+ VERSION = '8.0.0.alpha.4'
3
3
  end
@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'neo4j.rb')
2
2
 
3
3
  module Neo4j
4
4
  module Generators
5
- class Migration < ::Neo4j::Generators::Base
6
- def create_migration_file
7
- real_file_name = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}_#{file_name.parameterize}"
8
- @migration_class_name = file_name.camelize
5
+ class MigrationGenerator < ::Rails::Generators::NamedBase
6
+ include ::Neo4j::Generators::SourcePathHelper
7
+ include ::Neo4j::Generators::MigrationHelper
9
8
 
10
- template 'migration.erb', File.join('db/neo4j/migrate', real_file_name)
9
+ def create_migration_file
10
+ migration_template 'migration.erb'
11
11
  end
12
12
  end
13
13
  end
@@ -1,6 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'neo4j.rb')
2
2
 
3
- class Neo4j::Generators::ModelGenerator < Neo4j::Generators::Base #:nodoc:
3
+ class Neo4j::Generators::ModelGenerator < Rails::Generators::NamedBase #:nodoc:
4
+ include ::Neo4j::Generators::SourcePathHelper
5
+ include ::Neo4j::Generators::MigrationHelper
6
+
4
7
  argument :attributes, type: :array, default: [], banner: 'field:type field:type'
5
8
 
6
9
  check_class_collision
@@ -13,6 +16,7 @@ class Neo4j::Generators::ModelGenerator < Neo4j::Generators::Base #:nodoc:
13
16
 
14
17
  def create_model_file
15
18
  template 'model.erb', File.join('app/models', class_path, "#{singular_name}.rb")
19
+ migration_template 'migration.erb'
16
20
  end
17
21
 
18
22
  protected
@@ -0,0 +1,9 @@
1
+ class <%= @migration_class_name %> < Neo4j::Migrations::Base
2
+ def up
3
+ add_constraint :<%= class_name %>, :uuid
4
+ end
5
+
6
+ def down
7
+ drop_constraint :<%= class_name %>, :uuid
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ class <%= @migration_class_name %> < Neo4j::Migrations::Base
2
+ def up
3
+ <% @schema.each do |type, data|
4
+ data.each do |element| %>
5
+ add_<%= type %> <%= element[:label].inspect %>, <%= element[:property_name].inspect %>, force: true
6
+ <% end
7
+ end %>
8
+ end
9
+
10
+ def down
11
+ <% @schema.each do |type, data|
12
+ data.each do |element| %>
13
+ drop_<%= type %> <%= element[:label].inspect %>, <%= element[:property_name].inspect %>
14
+ <% end
15
+ end %>
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'neo4j.rb')
2
+
3
+ module Neo4j
4
+ module Generators
5
+ class UpgradeV8Generator < ::Rails::Generators::Base
6
+ include ::Neo4j::Generators::SourcePathHelper
7
+ include ::Neo4j::Generators::MigrationHelper
8
+
9
+ def create_upgrade_v8_file
10
+ @schema = load_all_models_schema!
11
+ migration_template 'migration.erb'
12
+ end
13
+
14
+ def file_name
15
+ 'upgrate_to_v8'
16
+ end
17
+
18
+ private
19
+
20
+ def load_all_models_schema!
21
+ Rails.application.eager_load!
22
+ initialize_all_models!
23
+ Neo4j::ModelSchema.legacy_model_schema_informations
24
+ end
25
+
26
+ def initialize_all_models!
27
+ models = Neo4j::ActiveNode.loaded_classes
28
+ models.map(&:ensure_id_property_info!)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,19 +1,38 @@
1
1
  require 'rails/generators/named_base'
2
2
  require 'rails/generators/active_model'
3
3
 
4
-
5
4
  module Neo4j
6
5
  module Generators #:nodoc:
7
6
  end
8
7
  end
9
8
 
10
- class Neo4j::Generators::Base < ::Rails::Generators::NamedBase #:nodoc:
11
- def self.source_root
12
- @_neo4j_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
13
- 'neo4j', generator_name, 'templates'))
9
+ module Neo4j::Generators::MigrationHelper
10
+ extend ActiveSupport::Concern
11
+
12
+ def migration_file_name(file_name)
13
+ "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}_#{file_name.parameterize}.rb"
14
+ end
15
+
16
+ def migration_template(template_name)
17
+ real_file_name = migration_file_name(file_name)
18
+ @migration_class_name = file_name.camelize
19
+
20
+ template template_name, File.join('db/neo4j/migrate', real_file_name)
14
21
  end
15
22
  end
16
23
 
24
+ module Neo4j::Generators::SourcePathHelper
25
+ extend ActiveSupport::Concern
26
+
27
+ module ClassMethods
28
+ def source_root
29
+ @_neo4j_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
30
+ 'neo4j', generator_name, 'templates'))
31
+ end
32
+ end
33
+ end
34
+
35
+
17
36
  class Neo4j::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc:
18
37
  def self.all(klass)
19
38
  "#{klass}.all"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0.alpha.2
4
+ version: 8.0.0.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Brian Underwood, Chris Grigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter
@@ -226,6 +226,7 @@ files:
226
226
  - Gemfile
227
227
  - README.md
228
228
  - bin/neo4j-jars
229
+ - bin/rake
229
230
  - config/locales/en.yml
230
231
  - config/neo4j/add_classnames.yml
231
232
  - config/neo4j/config.yml
@@ -311,6 +312,7 @@ files:
311
312
  - lib/neo4j/shared/initialize.rb
312
313
  - lib/neo4j/shared/marshal.rb
313
314
  - lib/neo4j/shared/mass_assignment.rb
315
+ - lib/neo4j/shared/permitted_attributes.rb
314
316
  - lib/neo4j/shared/persistence.rb
315
317
  - lib/neo4j/shared/property.rb
316
318
  - lib/neo4j/shared/query_factory.rb
@@ -330,7 +332,10 @@ files:
330
332
  - lib/rails/generators/neo4j/migration/migration_generator.rb
331
333
  - lib/rails/generators/neo4j/migration/templates/migration.erb
332
334
  - lib/rails/generators/neo4j/model/model_generator.rb
335
+ - lib/rails/generators/neo4j/model/templates/migration.erb
333
336
  - lib/rails/generators/neo4j/model/templates/model.erb
337
+ - lib/rails/generators/neo4j/upgrade_v8/templates/migration.erb
338
+ - lib/rails/generators/neo4j/upgrade_v8/upgrade_v8_generator.rb
334
339
  - lib/rails/generators/neo4j_generator.rb
335
340
  - neo4j.gemspec
336
341
  homepage: https://github.com/neo4jrb/neo4j/