Tutorial: migrate plugin schemas using Ruby on Rails 1.2

Writing plugins is an essential task for a ninja ruby on rails programmer, plugins are flexible, portable and helps maintaining the application code really clean.

But, what happens when you need to create a startup database schema for your plugin? Obviously you cannot attach a .sql file just next to README… this is not the Ruby on Rails way!

Luckily our problems are ended! Using the Rails 1.2 RC1 version and 3 plugins you can add a marvelous db:migrate:plugins task to your app!

First of all freeze rails at the 1.2 RC1 version:

rake rails:freeze:edge TAG=rel_1-2-0_RC1

Then install the three required plugins:

  • Plugin dependencies
  • Loaded plugins
  • Plugin migrations

Now just put your plugin migrations inside the plugin db folder and you can finally use tasks like.

rake db:migrate:plugins

rake db:migrate:plugins PLUGIN=acts_as_random

rake db:migrate:plugins PLUGIN=acts_as_random VERSION=3

Leave a Comment