Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

active_data_migrations

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rakeTasks
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 active_data_migrations.gemspec
README.md

Overview

ActiveDataMigrations is a Ruby gem that allows developers to set up multiple migration locations, each of which can be run independent of one another. This library sits on top of ActiveRecord so all standard migration features remain available.

This is particularly useful in cases where you want to separate your data migrations from your schema migrations or where you have multiple steps in your migration process that must have other steps invoked throughout.

Installation

$ gem install active_data_migrations

Usage

ActiveDataMigrations runs just like a normal migration only it has the ability to point to other source directories. Set up your migration files just like you do for a standard migration, only put them in a different directory.

Running the following will execute all migrations in the default 'db/data' directory:

$ rake db:data:migrate

To specify an alternative directory simply pass the MIGRATE_PATH argument:

$ rake db:data:migrate MIGRATE_PATH=/db/alt_migration_path

Example

For example, if we have the following directory structure:

db/
    schema/
    data/
    other_data/

and we need to run a migration, load some data, do some other task, then load the rest of our data we'd perform the following series of events.

Migrate the schema:

$ rake db:migrate

Migrate the initial data set:

$ rake db:data:migrate

After performing our other tasks, migrate the additional data set:

$ rake db:data:migrate MIGRATE_PATH=/db/other_data

Things to Note

There are a few things to note when using this tool:

  • The schema_migrations directory is shared across ALL MIGRATIONS. This means that you should make it a practice to have unique identifiers for ALL migration files across ALL migration directories. A good way to do this is to use the date and time for the identifier, such as "201207062043_update_some_data.rb".
  • ActiveDataMigrations has been tested with Rails 3. It is not guaranteed to work with other versions of Rails or as a stand alone library.
  • It doesn't list ActiveRecord as a dependency but instead assumes you have installed it already. This ensures that the version of ActiveRecord installed is always the one you plan to use anyhow.
  • Since this simply sits on top of ActiveRecord migrations you can also use it to run a standard schema migration by setting the migrate path to /db/schema (or wherever you have configured your schema root to be).

Contributing

I welcome any contributions anyone is wanting or willing to give. To contribute to the project you can contact me via: http://www.McDonaldLand.info.

License

ActiveDataMigrations is released under the MIT license:

http://www.opensource.org/licenses/MIT


Copyright © 2012 Jason McDonald (www.McDonaldLand.info)

Something went wrong with that request. Please try again.