Migrating Data in Rails Migrations

When I first started using Rails, one of the first things I fell in love with were migrations. I had been working on a web application in PERL that used a set of ad-hoc sql to create and manage the database. It seemed like everybody had a slightly different database which made making changes to production terrifying. With Rails, migrations made the process of modifying the database schema simple and repeatable.

Migrations are good for more than just migrating your database schema. I also use them frequently for creating or modifying required configuration data. I’ve found that many developers make a simple mistake when using migrations for modifying data, they don’t redefine ActiveRecord models. Not redefining models can cause a lot of pain in the future as the Rails Guides explain.