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 generate a new migration and put all differencies between plan.rb and your current database schema! You can migrate immediately, or add some more tweaks to your migration, or something else.
Why is it great? Because you don’t need to remember all that syntax like change_column, add_column, etc - you just modify your schema (in the plan.rb).
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
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 [ [email protected] ]