Skip to content

Neo4j v3 Migrations

subvertallchris edited this page Sep 21, 2014 · 11 revisions

Migrations

The following documents pre-rerelease features. Documentation is being added ahead of time so it doesn't slip through the cracks after merge.

Migrations are an easy way to make database-wide changes. Unlike ActiveRecord, Neo4j.rb does not (yet?) keep track of migrations to run during a new deployment; rather, it offers a process for performing one-time or scheduled tasks as needed.

Usage is simple.

Include require 'neo4j/tasks/rails' in your Rakefile.

To run, rake neo4j:migrate[task_name,subtask]

Gem-provided migrations are found in neo4j/migration.rb but if you have a custom task, put it in /db/neo4j-migrate/ and name it to match your task name. The contents of your file should be the classified version of the task name: task add_id_property would have file add_id_property.rb and contain class AddIdProperty.

In the file, your class must inherit from Neo4j::Migration and contain a migrate method, to be executed when no subtask is provided at the command line. As an example rake neo4j:migrate[add_id_property] is essentially equivalent to Neo4j::Migration::AddIdProperty.new.migrate.

If you have other tasks that may be helpful, such as setup, define those as instance methods in your class and call from command line as rake neo4j:migrate[your_task,extra_method].

Gem-Provided Tasks

add_id_property

To use, run rake neo4j:migrate[add_id_property,setup] and modify add_id_property.yml, created in your Rails app's db/neo4j-migrate/ folder. It contains one line, models = []. Add the names of models that need IDs generated to that array.

models = [Student,Lesson,Exam]

rake neo4j:migrate[add_id_property] to execute. It will load the model, find its given ID property and generation method, and populate that property on all nodes of that class where an ID is not already assigned. It does this in batches of up to 900 at a time.

Clone this wiki locally