A thin wrapper to use Rails Migrations in non Rails projects
Switch branches/tags
Nothing to show
Pull request Compare This branch is 5 commits ahead, 439 commits behind thuss:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a tiny project that allows you to use Rails migrations in non-Rails (and non Ruby) projects. I created it because not all of my projects are on Rails but I still think Rails migrations are the best way to manage a database schema. For this code to work you need Ruby, Gems, ActiveRecord, Rake and a suitable database driver installed.

I just got this working to the point where it met my needs but if you'd like to contribute patches to make it better please do! One thing that would be great would be a new_migration script that works just like "script/generate migration"

Email me at todd dot huss dot work at gmail dot com if you have a patch that adds functionality or fixes a bug. Or post a comment here:

This work is based on Lincoln Stoll's blog post: http://lstoll.net/2008/04/stand-alone-activerecord-migrations/
and David Welton's post http://journal.dedasys.com/2007/01/28/using-migrations-outside-of-rails


Most Linux systems have pre-existing packages for Ruby and Ruby gems so in most cases that should be pretty straightforward. Once Ruby and Gem is installed, as root run:
gem install -y activerecord rake mysql

cd standalone-migrations/config
cp database_sample.yml database.yml
edit database.yml (and change settings for your database)
cd ../
rake db:migrate (this will just create the schema_migrations table)
(If you're familiar with rails there are also the tasks db:schema:dump and db:schema:load)

A good source to learn how to use migrations is:
or if you're lazy you can just use the execute method to execute raw SQL

def self.up
  execute "insert into foo values (123,'something');"

def self.down
  execute "delete from foo where field='something';"

To create a new database migration run:

rake db:new_migration name="us_131_some_project"

This will create migrations/XXXXXXXXXXXXXX_us_131_some_project.rb

or also like:

rake db:new_migration name=FooBarMigration

edit migrations/XXXXXXXXXXXXXX_us_131_some_project.rb

and fill in the up and down migrations. To apply your newest migration

rake db:migrate

To migrate to a specific version (for example to rollback)

rake db:migrate VERSION=20081220234130