October 22 2008

Migration Generator for Extensionsby railsdog

Extensions have always provided a handy generator for migrations that took care of the new model case. If you had a foo_extension and wanted to create a bar model you could always use:

script/generate extension_model foo bar

This would yield the following:

exists  app/models/
exists  spec/models/
create  app/models/bar.rb
create  spec/models/bar_spec.rb
create  vendor/extensions/foo/db/migrate
create  db/migrate/20081022232711_create_bars.rb

That works most of the time but if you decide to further modify the foo table (or if you need a migration unrelated to a specific model) then you’re pretty much stuck. What would be really handy is a generator that generates additional migrations for an extension using the current timestamp that standard migrations receive.

Thanks to a brand new edge feature, this is now possible.

script/generate extension_migration foo add_foo_property

This now gives you the desired migration:

exists  vendor/extensions/foo/db/migrate
create  vendor/extensions/foo/db/migrate/20081022232740_add_foo_property.rb