neo4jrb/neo4j — pull request #480 by subvertallchris (2014-09-21 01:40:06+00:00)
Title: introduces migrations, add_id_property task

An easy way to make systemwide changes. Unlike ActiveRecord, it 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.

```ruby
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; thus, `rake neo4j:migrate[add_id_property]` will call Neo4j::Migration::AdIdProperty.new.migrate.

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

This includes one built-in task, `add_id_property`. `rake neo4j:migrate[add_id_property,setup]` will create `add_id_property.yml` at `db/neo4j-migrate/`. Inside the provided `models` array, give it constants of classes that need IDs (maybe old data, maybe data added by something other than ActiveNode) and run it. `rake neo4j:migrate[add_id_property]`. It does it in batches of 900 nodes due to possible memory limitations; I'd love to find a way to bring this higher reliably.

No tests for this, unfortunately. Just finished up and I gotta run, but I tested the built-in task thoroughly with local data.