Data Plan
A tool for easy migration generation. Works with Sinatra/ActiveRecord and with Rails too.
Usage
Before use in Sinatra, install ‘sinatra-activerecord’ gem. It extends Sinatra with extension methods and Rake tasks for dealing with
an SQL database using the ActiveRecord ORM. Follow it’s instructions and create a Rakefile with migration commands. After that you can invoke ‘rake db:create_migration’ and get migrations.
And then, magic begins.
-
Add to Rakefile:
require ‘data_plan/generators/migration/sinatra’
-
Create db/plan.rb file and describe desired db schema in it.
Now, when you create a migration, DataPlan will find and put all differencies between plan.rb and your current database schema!
That’s it, you get migration code for free. You can migrate immediately, or add some more tweaks to your migration, or something else.
Why is it great?
-
You have the one place (plan.rb) where you write db schema and
comments on it.
-
You don’t need to remember all that syntax like
change_column, add_column, etc. You just write the schema in plan.rb file and get migrations code for free.
Nice bonus: migrations are automatically named (of course you may override name suggested).
How to use with Rails
Copy from the gem the folder
GEMROOT/lib/data_plan/generators/migration/*
to the Rails project as follows:
YOURAPPROOT/lib/generators/migration/*
Thats it, Data Plan now in your rails app, and you can invoke ‘script/generate migration’ and get migrations auto-generated as described above.
How to install
gem install data_plan
Ruby versions
Because Sinatra-ActiveRecord works only with Ruby 1.9, DataPlan works with 1.9 for Sinatra. For Rails, it should work both for 1.8 and 1.9. Only (Sinatra-ActiveRecord 1.1.2 + ruby 1.9) and (Rails 2.3 + ruby 1.8) was tested.
Todo
Indices are partially supported at the moment.
Changelog
Workaround on views. Thanks to Cyril Boswell.
Legal
Found a bug? Fix it and email pull request to me: [email protected]
Want to add a feature? Implement it and email the patch!
Pavel Vasev [ [email protected] ]
Released under the MIT license (included)
p.s. Schema-Definition plugin is hugely based on Auto-Migrations by PJ Hyett