Skip to content

Instantly share code, notes, and snippets.

@RyanSnodgrass
Last active March 14, 2017 20:38
Show Gist options
  • Select an option

  • Save RyanSnodgrass/55b9f58efba9ac84679b5ef87a272186 to your computer and use it in GitHub Desktop.

Select an option

Save RyanSnodgrass/55b9f58efba9ac84679b5ef87a272186 to your computer and use it in GitHub Desktop.

Upgrading neo4j.rb to 8.x

Clear out old schema

The old way of doing schemas in neo4j.rb involved adding an index property on the model. This is no longer valid and you have to utilize the migration feature added in 8.0.

You can browse the schema on the localhost:747/browser window in your browser by running the :schema command

To clear it out you run these commands in the rails console thanks to stackoverflow

  conn = Faraday.new(url: "http://localhost:7474")
  response = conn.get('/db/data/schema/constraint/')
  constraints = JSON.parse(response.body)
  constraints.each do |constraint|
    Neo4j::ActiveBase.current_session.query("DROP CONSTRAINT ON (label:`#{constraint['label']}`) ASSERT label.#{constraint['property_keys'].first} IS UNIQUE")
  end 

  response = conn.get('/db/data/schema/index/')
  indexes = JSON.parse(response.body)
  indexes.each do |index|
    Neo4j::ActiveBase.current_session.query("DROP INDEX ON :`#{index['label']}`(#{index['property_keys'].first})")
  end

Create Migration

The next thing needed is to create a migration. Check out the neo4jrb docs for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment