neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Minor release of v9 with seabolt support? #1599

Closed ghost closed 4 years ago

ghost commented 4 years ago

I've been experimenting with the seabolt driver on my v9.6 application, it's a bit tricky to set-up, but once done it's fast and reliable -- everything works except one thing: attempting to load the schema results in a Neo4j::Driver::Exceptions::ClientException "Cannot perform data updates in a transaction that has performed schema updates.". Looking at the 9.6.1 source locally, modifying lib/neo4j/tasks/migration.rake from

Neo4j::ActiveBase.run_transaction do
  Neo4j::Migrations::Schema.synchronize_schema_data(...)
  runner = Neo4j::Migrations::Runner.new
  runner.mark_versions_as_complete(schema_data[:versions]) # Run in test mode?
end

to

Neo4j::ActiveBase.run_transaction do
  Neo4j::Migrations::Schema.synchronize_schema_data(...)
end
Neo4j::ActiveBase.run_transaction do
   runner = Neo4j::Migrations::Runner.new
   runner.mark_versions_as_complete(schema_data[:versions]) # Run in test mode?
end

Fixes the issue. I see you have already done the same in master.

So could I request that there is a minor release of the v9 branch (9.6.2?) which back-ports this two-line fix enabling use of Seabolt? I'll be jumping on v10 as soon as it's out of beta, but I'm sure there are those who will be using v9 for some time yet.

klobuczek commented 4 years ago

Yes, this is probably possible with the right version of neo4j-ruby-driver. @jjg-dressipi could make a PR to the 9.6.x branch with all the changes needed to make it work of if only the changes above could you describe the tricks you had to apply?

ghost commented 4 years ago

Many thanks, I'll make that PR shortly.

May be best to describe the changes here. This is for a Rails 5 API-only application.

First, you need to have some configuration options set in config/application.rb, and when those are found your config/neo4j.yml is ignored. This means that neo4j.rb will use the default (http) URL and you get errors like "ArgumentError: Invalid URL http://localhost:7474" even though you have specified the bolt protocol and URL in config/neo4j.yml. So move all options defined in config/neo4j.yml into config/application.rb and the per-environment files config/environments/*.rb as follows

Modify config/application.rb to have the extra lines

require 'neo4j/core/cypher_session/adaptors/driver'
require 'neo4j_ruby_driver'
  : 
 module Neo4jUserUser 
    : 
    config.neo4j.session.type = :bolt
    config.neo4j.session.options = {
      ssl: false,
      adaptor_class: Neo4j::Core::CypherSession::Adaptors::Driver
    }

Modify config/environments/test.rb adding the line

config.neo4j.session.url = 'bolt://localhost:7572'

Modify config/environments/development.rb adding the line

config.neo4j.session.url = 'bolt://localhost:7572'

and so on.

klobuczek commented 4 years ago

@jjg-dressipi neo4j-9.6.2 released! in your application.rb only adaptor_class is necessary, the other 2 are ignored. One important thing to find out is which version of neo4j-ruby-driver is compatible with 9.6.2. I can say for sure that the newest 0.4.0 is not. I didn't pay attention to that as so far the driver was supporting only beta versions of activegraph.

ghost commented 4 years ago

Great -- thanks!

ghost commented 4 years ago

Just a note to confirm that this fixes the issue with my application: my Gemfile now reads

gem 'neo4j', '~> 9.6.2'
gem 'neo4j-ruby-driver', '< 0.4.0'
  : 

which should coerce and maintain the version restrictions mentioned above by @klobuczek