neo4j 8.0.18 → 8.1.0.rc.1

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: d308aa373875c2a15c4252c06d1450d192467fc8
4
- data.tar.gz: 29c48905187431fdc1f8363cc061a7ec37edf088
3
+ metadata.gz: 48710007e99e018577ac5dfd171806ab778f4e14
4
+ data.tar.gz: 5f36d371ba8289fbf1412cf064330763f97019a8
5
5
  SHA512:
6
- metadata.gz: 685b2b49d58bdc6d8d63eade6e8f03b88ac18ac4dcc6bb3286258c520dcdc4796cc8d4296e65cbfa08a9eab50b4d74cc74261133c3794bda00b1f306cf2cfb3d
7
- data.tar.gz: 024d8b4bb07c397ab8ef356753712430f078bc35db9c4e05cb769e7fde1defdc655fe26266294be2c7410a9ada461fccb6563985cb1f18aa79865777bc1b028f
6
+ metadata.gz: 2ecbd9e36ba67936bb7106e5d2897d75a2c9acc5f7c0733aaa77f6d8e41d56e2b03dda129010338b2e014c511e118d146d628be03c0877ec3c30c22c27ca7f5a
7
+ data.tar.gz: 644b80a450e056e0df194d5288e80a87e48052853568c1ef41dfea694f918e5b6d06f67ecd1da9b222dc57fa602619f5c50b48722a74d596736d1d8e612c87ae
data/CHANGELOG.md CHANGED
@@ -3,11 +3,15 @@ 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
- ## [8.0.18] 2016-06-04
6
+ ## [Unreleased]
7
7
 
8
- ### Fixed
8
+ ### Added
9
+
10
+ - Created `neo4j:schema:dump` and `neo4j:schema:load` rake tasks to create `schema.yml` files which can be checked into the repository for quick setup of a fresh database
11
+
12
+ ### Changed
9
13
 
10
- - Migration name when generating a model shouldn't be the same as the model (see #1387 / thanks @thefliik and @apotonick)
14
+ - Removed `before` and `after` callback options from associations (model callbacks still exist)
11
15
 
12
16
  ## [8.0.17] 2016-05-03
13
17
 
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Welcome to Neo4j.rb
2
2
 
3
- **FOR INFORMATION ABOUT NEO4J 3.0 SUPPORT, SEE [VERSION SUPPORT](https://github.com/neo4jrb/neo4j#neo4j-version-support) and [FEATURE SUPPORT](https://github.com/neo4jrb/neo4j#neo4j-feature-support) sections**
4
-
5
- **ALSO NOTE THAT MASTER IS CURRENT IN FLUX IN PREPARATION FOR AN ALPHA OF 8.0 AND IT IS NOT RECOMMENDED TO BE USED**
6
-
7
3
  ## Code Status
8
4
 
9
- [![Build Status](https://secure.travis-ci.org/neo4jrb/neo4j.png?branch=master)](http://travis-ci.org/neo4jrb/neo4j) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j?branch=master) [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j.png)](https://codeclimate.com/github/neo4jrb/neo4j) [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j/reviews/master)
5
+ [![Actively Maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d)
6
+ [![Build Status](https://secure.travis-ci.org/neo4jrb/neo4j.png?branch=master)](http://travis-ci.org/neo4jrb/neo4j)
7
+ [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j?branch=master)
8
+ [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j.png)](https://codeclimate.com/github/neo4jrb/neo4j)
9
+ [![PullReview stats](https://www.pullreview.com/github/neo4jrb/neo4j/badges/master.svg?)](https://www.pullreview.com/github/neo4jrb/neo4j/reviews/master)
10
10
 
11
11
  ## Issues
12
12
 
@@ -60,26 +60,28 @@ Neo4j.rb v4.1.0 was released in January of 2015. Its changes are outlined [here]
60
60
  | 2.2.x | No | No | Yes | Yes |
61
61
  | 2.3.x | No | No | Yes | Yes |
62
62
  | 3.0.x | No | No | No | Yes |
63
+ | 3.1.x | No | No | No | Yes |
63
64
 
64
65
  `*` Neo4j.rb >= 4.x doesn't support Neo4j versions before 2.1.5. To use 2.1.x you should upgrade to a version >= 2.1.5
65
66
 
66
67
  ## Neo4j feature support
67
68
 
68
- | **Neo4j Feature** | v2.x | v3.x | >= v4.x | >= 8.x (coming soon) |
69
- |----------------------------|--------|------|---------|----------------------|
70
- | Bolt Protocol | No | No | No | Yes (coming soon) |
71
- | Auth | No | No | Yes | Yes |
72
- | Remote Cypher | Yes | Yes | Yes | Yes |
73
- | Transactions | Yes | Yes | Yes | Yes |
74
- | High Availability | No | Yes | Yes | Yes |
75
- | Embedded JVM support | Yes | Yes | Yes | Yes |
69
+ | **Neo4j Feature** | v2.x | v3.x | >= v4.x | >= 8.x |
70
+ |----------------------------|--------|------|---------|--------|
71
+ | Bolt Protocol | No | No | No | Yes |
72
+ | Auth | No | No | Yes | Yes |
73
+ | Remote Cypher | Yes | Yes | Yes | Yes |
74
+ | Transactions | Yes | Yes | Yes | Yes |
75
+ | High Availability | No | Yes | Yes | Yes |
76
+ | Embedded JVM support | Yes | Yes | Yes | Yes |
76
77
 
77
- ## Modern (3.x/4.X) Documentation
78
+ ## Documentation
78
79
 
79
80
  * [Website](http://neo4jrb.io/) (for an introduction)
80
- * [Wiki](https://github.com/neo4jrb/neo4j/wiki/Neo4j.rb-v4-Introduction)
81
+ * [readthedocs](http://neo4jrb.readthedocs.io/)
82
+ * **Note:** Our GitHub Wiki pages have outdated information. We are in the process of moving all documentation to [readthedocs](http://neo4jrb.readthedocs.io/)
81
83
 
82
- ## Legacy (2.x) Documentation
84
+ ## Legacy (<= 2.x) Documentation
83
85
 
84
86
  * [README](https://github.com/neo4jrb/neo4j/tree/2.x)
85
87
  * [Wiki](https://github.com/neo4jrb/neo4j/wiki/Neo4j%3A%3ARails-Introduction)
@@ -95,8 +97,6 @@ Neo4j.rb v4.1.0 was released in January of 2015. Its changes are outlined [here]
95
97
  * [Brian Underwood](https://github.com/cheerfulstoic)
96
98
  * [Chris Grigg](https://github.com/subvertallchris)
97
99
 
98
- * Consulting support? Contact [Chris](http://subvertallmedia.com/) and/or [Brian](http://www.brian-underwood.codes/)
99
-
100
100
  ## Contributing
101
101
 
102
102
  Always welcome! Please review the [guidelines for contributing](CONTRIBUTING.md) to this repository.
@@ -103,15 +103,6 @@ module Neo4j
103
103
  @target_class = class_const
104
104
  end
105
105
 
106
- def callback(type)
107
- @callbacks[type]
108
- end
109
-
110
- def perform_callback(caller, other_node, type)
111
- return if callback(type).nil?
112
- caller.send(callback(type), other_node)
113
- end
114
-
115
106
  def relationship_type(create = false)
116
107
  case
117
108
  when relationship_class
@@ -191,7 +182,6 @@ module Neo4j
191
182
  @relationship_type = options[:type] && options[:type].to_sym
192
183
 
193
184
  @model_class = options[:model_class]
194
- @callbacks = {before: options[:before], after: options[:after]}
195
185
  @origin = options[:origin] && options[:origin].to_sym
196
186
  @dependent = options[:dependent].try(:to_sym)
197
187
  @unique = options[:unique]
@@ -201,13 +201,9 @@ module Neo4j
201
201
  other_nodes.each do |other_node|
202
202
  other_node.save unless other_node.neo_id
203
203
 
204
- return false if @association.perform_callback(@start_object, other_node, :before) == false
205
-
206
204
  @start_object.association_proxy_cache.clear
207
205
 
208
206
  _create_relationship(other_node, properties)
209
-
210
- @association.perform_callback(@start_object, other_node, :after)
211
207
  end
212
208
  end
213
209
  end
@@ -40,7 +40,7 @@ module Neo4j::ActiveRel
40
40
  # @param [Symbol, String] name of the attribute to increment
41
41
  # @param [Integer, Float] amount to increment
42
42
  def concurrent_increment!(attribute, by = 1)
43
- increment_by_query! query_as(:n), attribute, by
43
+ increment_by_query! query_as(:n), attribute, by, :r
44
44
  end
45
45
 
46
46
  def create_model
@@ -10,6 +10,8 @@ module Neo4j
10
10
 
11
11
  class << self
12
12
  def check_for_pending_migrations!
13
+ return if Neo4j::Config.configuration['skip_migration_check']
14
+
13
15
  runner = Neo4j::Migrations::Runner.new
14
16
  pending = runner.pending_migrations
15
17
  fail ::Neo4j::PendingMigrationError, pending if pending.any?
@@ -52,6 +52,18 @@ module Neo4j
52
52
  all_migrations.select { |migration| !up?(migration) }
53
53
  end
54
54
 
55
+ def complete_migration_versions
56
+ @schema_migrations.map(&:migration_id)
57
+ end
58
+
59
+ def mark_versions_as_complete(versions)
60
+ Neo4j::ActiveBase.new_query
61
+ .with('{versions} AS versions').params(versions: versions).break
62
+ .unwind(version: :versions).break
63
+ .merge('(:`Neo4j::Migrations::SchemaMigration` {version: version})')
64
+ .exec
65
+ end
66
+
55
67
  def status
56
68
  output STATUS_TABLE_FORMAT, *STATUS_TABLE_HEADER
57
69
  output SEPARATOR
@@ -0,0 +1,44 @@
1
+ module Neo4j
2
+ module Migrations
3
+ module Schema
4
+ class << self
5
+ def fetch_schema_data(session)
6
+ {constraints: fetch_constraint_descriptions(session).sort,
7
+ indexes: fetch_index_descriptions(session).sort}
8
+ end
9
+
10
+ def synchronize_schema_data(session, schema_data, remove_missing)
11
+ queries = []
12
+ queries += drop_and_create_queries(fetch_constraint_descriptions(session), schema_data[:constraints], remove_missing)
13
+ queries += drop_and_create_queries(fetch_index_descriptions(session), schema_data[:indexes], remove_missing)
14
+ session.queries do
15
+ queries.each { |query| append query }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def fetch_constraint_descriptions(session)
22
+ session.query('CALL db.constraints()').map(&:description)
23
+ end
24
+
25
+ def fetch_index_descriptions(session)
26
+ session.query('CALL db.indexes()').reject do |row|
27
+ # These indexes are created automagically when the corresponding constraints are created
28
+ row.type == 'node_unique_property'
29
+ end.map(&:description)
30
+ end
31
+
32
+ def drop_and_create_queries(existing, specified, remove_missing)
33
+ [].tap do |queries|
34
+ if remove_missing
35
+ (existing - specified).each { |description| queries << "DROP #{description}" }
36
+ end
37
+
38
+ (specified - existing).each { |description| queries << "CREATE #{description}" }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -106,7 +106,7 @@ module Neo4j
106
106
 
107
107
  def validation_error_message(messages)
108
108
  <<MSG
109
- Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database. Run the following to create them:
109
+ Some schema elements were defined by the model (which is no longer supported), but they do not exist in the database. Run the following to create them if you haven't already:
110
110
 
111
111
  #{messages[:constraint].join("\n")}
112
112
  #{messages[:index].join("\n")}
data/lib/neo4j/railtie.rb CHANGED
@@ -43,6 +43,8 @@ module Neo4j
43
43
  # Starting Neo after :load_config_initializers allows apps to
44
44
  # register migrations in config/initializers
45
45
  initializer 'neo4j.start', after: :load_config_initializers do |app|
46
+ app.config.neo4j.skip_migration_check = true if Rails.env.test?
47
+
46
48
  neo4j_config = ActiveSupport::OrderedOptions.new
47
49
  app.config.neo4j.each { |k, v| neo4j_config[k] = v } if app.config.neo4j
48
50
 
@@ -11,6 +11,7 @@ module Neo4j
11
11
  include ActiveModel::Validations::Callbacks
12
12
  # after_find is triggered by the `find` method defined in lib/neo4j/active_node/id_property.rb
13
13
  define_model_callbacks :initialize, :find, only: :after
14
+ define_model_callbacks :create_commit, :update_commit, :destroy_commit, only: :after
14
15
  define_model_callbacks :save, :create, :update, :destroy, :touch
15
16
  end
16
17
 
@@ -20,6 +21,7 @@ module Neo4j
20
21
 
21
22
  def destroy #:nodoc:
22
23
  tx = Neo4j::ActiveBase.new_transaction
24
+ tx.root.after_commit { run_callbacks(:destroy_commit) {} }
23
25
  run_callbacks(:destroy) { super }
24
26
  rescue
25
27
  @_deleted = false
@@ -49,13 +51,15 @@ module Neo4j
49
51
  end
50
52
 
51
53
  def create_model #:nodoc:
52
- self.class.run_transaction do
54
+ self.class.run_transaction do |tx|
55
+ tx.root.after_commit { run_callbacks(:create_commit) {} }
53
56
  run_callbacks(:create) { super }
54
57
  end
55
58
  end
56
59
 
57
60
  def update_model(*) #:nodoc:
58
- self.class.run_transaction do
61
+ self.class.run_transaction do |tx|
62
+ tx.root.after_commit { run_callbacks(:update_commit) {} }
59
63
  run_callbacks(:update) { super }
60
64
  end
61
65
  end
@@ -19,7 +19,6 @@ namespace :neo4j do
19
19
  task :allow_migrations do
20
20
  Neo4j::Migrations.currently_running_migrations = true
21
21
  end
22
-
23
22
  desc 'Run a script against the database to perform system-wide changes'
24
23
  task :legacy_migrate, [:task_name, :subtask] => :environment do |_, args|
25
24
  path = Rake.original_dir
@@ -46,11 +45,63 @@ namespace :neo4j do
46
45
  Rake::Task['neo4j:migrate:all'].invoke
47
46
  end
48
47
 
48
+ # TODO Make sure these tasks don't run in versions of Neo4j before 3.0
49
+ namespace :schema do
50
+ SCHEMA_YAML_PATH = 'db/neo4j/schema.yml'
51
+
52
+ def check_neo4j_version_3
53
+ if Neo4j::ActiveBase.current_session.version > '3.0.0'
54
+ yield
55
+ else
56
+ puts 'WARNING: This task does not work for versions of Neo4j before 3.0.0'
57
+ end
58
+ end
59
+
60
+ desc 'Creates a db/neo4j/schema.yml file which represents the indexes / constraints in the Neo4j DB'
61
+ task :dump => :environment do
62
+ check_neo4j_version_3 do
63
+ require 'neo4j/migrations/schema'
64
+
65
+ schema_data = Neo4j::Migrations::Schema.fetch_schema_data(Neo4j::ActiveBase.current_session)
66
+
67
+ runner = Neo4j::Migrations::Runner.new
68
+ schema_data[:versions] = runner.complete_migration_versions.sort
69
+
70
+ FileUtils.mkdir_p(File.dirname(SCHEMA_YAML_PATH))
71
+ File.open(SCHEMA_YAML_PATH, 'w') { |file| file << schema_data.to_yaml }
72
+
73
+ puts "Dumped updated schema file to #{SCHEMA_YAML_PATH}"
74
+ end
75
+ end
76
+
77
+ desc "Loads a db/neo4j/schema.yml file into the database\nOptionally removes schema elements which aren't in the schema.yml file (defaults to false)"
78
+ task :load, [:remove_missing] => :environment do |t, args|
79
+ check_neo4j_version_3 do
80
+ require 'neo4j/migrations/schema'
81
+
82
+ args.with_defaults(remove_missing: false)
83
+
84
+ schema_data = YAML.load(File.read(SCHEMA_YAML_PATH))
85
+
86
+ Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query(&method(:puts))
87
+
88
+ Neo4j::ActiveBase.run_transaction do
89
+ Neo4j::Migrations::Schema.synchronize_schema_data(Neo4j::ActiveBase.current_session, schema_data, args[:remove_missing])
90
+
91
+ runner = Neo4j::Migrations::Runner.new
92
+ runner.mark_versions_as_complete(schema_data[:versions]) # Run in test mode?
93
+ end
94
+ end
95
+ end
96
+ end
97
+
49
98
  namespace :migrate do
50
99
  desc 'Run all pending migrations'
51
100
  task all: [:allow_migrations, :environment] do
52
101
  runner = Neo4j::Migrations::Runner.new
53
102
  runner.all
103
+
104
+ Rake::Task['neo4j:schema:dump'].invoke
54
105
  end
55
106
 
56
107
  desc 'Run a migration given its VERSION'
@@ -58,6 +109,8 @@ namespace :neo4j do
58
109
  version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
59
110
  runner = Neo4j::Migrations::Runner.new
60
111
  runner.up version
112
+
113
+ Rake::Task['neo4j:schema:dump'].invoke
61
114
  end
62
115
 
63
116
  desc 'Revert a migration given its VERSION'
@@ -65,6 +118,8 @@ namespace :neo4j do
65
118
  version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
66
119
  runner = Neo4j::Migrations::Runner.new
67
120
  runner.down version
121
+
122
+ Rake::Task['neo4j:schema:dump'].invoke
68
123
  end
69
124
 
70
125
  desc 'Print a report of migrations status'
@@ -93,6 +148,8 @@ namespace :neo4j do
93
148
  steps = (ENV['STEP'] || 1).to_i
94
149
  runner = Neo4j::Migrations::Runner.new
95
150
  runner.rollback(steps)
151
+
152
+ Rake::Task['neo4j:schema:dump'].invoke
96
153
  end
97
154
 
98
155
  # Temporary to help people change to 8.0
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '8.0.18'
2
+ VERSION = '8.1.0.rc.1'
3
3
  end
@@ -16,7 +16,7 @@ class Neo4j::Generators::ModelGenerator < Rails::Generators::NamedBase #:nodoc:
16
16
 
17
17
  def create_model_file
18
18
  template 'model.erb', File.join('app/models', class_path, "#{singular_name}.rb")
19
- migration_template 'migration.erb', 'create_'
19
+ migration_template 'migration.erb'
20
20
  end
21
21
 
22
22
  protected
@@ -1,4 +1,4 @@
1
- class Create<%= @migration_class_name.underscore.camelize %> < Neo4j::Migrations::Base
1
+ class <%= @migration_class_name.underscore.camelize %> < Neo4j::Migrations::Base
2
2
  def up
3
3
  add_constraint :<%= class_name %>, :uuid
4
4
  end
@@ -9,12 +9,12 @@ end
9
9
  module Neo4j::Generators::MigrationHelper
10
10
  extend ActiveSupport::Concern
11
11
 
12
- def migration_file_name(file_name, prefix = '')
13
- "#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{prefix}#{file_name.parameterize}.rb"
12
+ def migration_file_name(file_name)
13
+ "#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{file_name.parameterize}.rb"
14
14
  end
15
15
 
16
- def migration_template(template_name, prefix = '')
17
- real_file_name = migration_file_name(file_name, prefix)
16
+ def migration_template(template_name)
17
+ real_file_name = migration_file_name(file_name)
18
18
  @migration_class_name = file_name.camelize
19
19
 
20
20
  template template_name, File.join('db/neo4j/migrate', real_file_name)
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.18
4
+ version: 8.1.0.rc.1
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: 2017-06-05 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter
@@ -275,6 +275,7 @@ files:
275
275
  - lib/neo4j/migrations/helpers/schema.rb
276
276
  - lib/neo4j/migrations/migration_file.rb
277
277
  - lib/neo4j/migrations/runner.rb
278
+ - lib/neo4j/migrations/schema.rb
278
279
  - lib/neo4j/migrations/schema_migration.rb
279
280
  - lib/neo4j/model_schema.rb
280
281
  - lib/neo4j/paginated.rb
@@ -343,9 +344,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
343
344
  version: 2.1.9
344
345
  required_rubygems_version: !ruby/object:Gem::Requirement
345
346
  requirements:
346
- - - ">="
347
+ - - ">"
347
348
  - !ruby/object:Gem::Version
348
- version: '0'
349
+ version: 1.3.1
349
350
  requirements: []
350
351
  rubyforge_project: neo4j
351
352
  rubygems_version: 2.6.8