Standalone Migrations: Using Rails migrations in non Rails projects

Update 7/8/2009: With the latest batch of contributed patches standalone migrations now works just like Rails migrationsUpdate 12/26/2008: I switched standalone migrations to use a Rakefile instead of a Ruby script.

In my work managing websites I end up working in Ruby, Java, and PHP. In everything but Rails managing the schema requires rolling your own solution. As a result I’ve started using Rails migrations in non-Rails projects to manage the schema. It’s not much code but I figured others might benefit from it so I created a little Github project called standalone migrations.

Todd, there doesn’t seem to be any config/database_sample.yml file in the GitHub project when I download it. Are there any differences between the database.yml file here and one in a standard rails project? Can you still define different environments (development, production, etc.)? If so, where do you define them?

Now, I can pass RAILS_ENV as a parameter to db:migrate, like I can with Rails migrations, and it will use the ‘development’ environment by default.

Also, adding the following line at the end of the migrate task, to invoke the db:schema:dump task causes a schema.rb file to be dumped at the end of each migration, like it does in Rails. This is handy if you want to be able to use db:schema:load to set up a new environment from the schema.rb file.

Sad story, but I find I must use ActiveRecord 2.3.14 for my non-rails ruby application (Production database is MSSQL 2000). I’m thinking there is an older version of standalone_migrations I can use. Can you advise?

About Me

I live in San Francisco and am the Co-Founder of Two Bit Labs where we develop iPhone, iPad, and Android mobile apps for our clients. I love the mix of team leadership and working as a hands-on contributor. My technical passions include Swift, Kotlin, Ruby, Cloud Computing, and open-source software.

I also love to sail and my wife, daughter, and I sailed out the Golden Gate in 2007 on our 38 foot Hans Christian cutter (sailboat) on a 3 year cruise. Read about it at http://sailsugata.com.