Thursday, July 12, 2007

Rails Migrations Fu

Sexy Migrations



Err's Sexy Migrations plugin is just syntactic sugar but it sure is sweet, so sweet in fact that sexy is available in Edge Rails.

Data Migrations



Migrations aren't just about schema changes. They are also a great way to clean up your stored data, or to add default data (like an admin user). You've got to be careful though migrations and versioning have a somewhat uneasy relationship, your model classes may well change between writing the migration and applying it sometime in the future.

For complete safety you could stick to using pure SQL through helpers on ActiveRecord::Base.connection, or if you're careful you can still use ActiveRecord sugar but for safety you should redefine your model classes in your migrations, and stick to the basics.

Migrations Testing



If you're using a TDD approach (if not, why not?), you should write a simple migration test for every migration.


You can test
  • normal migrations

  • a complete migration from start to finish

  • and data migrations

0 comments: