MongoidMigration

ActiveRecord::Migration ported to Mongoid to run incremental/reversible migrations to manipulate/populate data in the database.

Rails 3.x

insert this line to Gemfile:

gem “mongoid_migration”, “~> 0.0.3”

Rails Generator

Run the generator to generate timestamped migration files:

rails generate mongoid_migration Thing

which generates a timestamped migration file: mongodb/migrate/20111114234935_thing.rb similar to AR.

The migration has 2 class methods defined, self.up - executed when migrating up and self.down - executed when migrating down. Obviously ActiveRecord::ConnectionAdapters::SchemaStatements methods have not been ported over, so don’t attempt to use them. (they make no sense for mongodb anyways)

The following rake tasks are available:

  • rake db:mongoid:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).

  • rake db:mongoid:migration:down # Runs the “down” for a given migration VERSION.

  • rake db:mongoid:migration:status # Display status of migrations

  • rake db:mongoid:migration:up # Runs the “up” for a given migration VERSION.

  • rake db:mongoid:rollback # Rolls migrations back to the previous version (specify steps w/ STEP=n).

  • rake db:mongoid:version # Retrieves the current schema version number

Contributing to MongoidMigration

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

This is the fork of ActiveRecord::Migrations ported to work with mongoid. All thanks should go to the Rails team.