I’m working on my first official migration that inserts data rather
than changing the structure of the database; there’s some data we’d
like to be present in any database, so it seems sensible to put it in
However, I’m realizing that it’s not all that simple. The obvious way
to do a data migration is to use the model class.
Imagine that I have an organization with a mandatory name and an
e.g. create_table :organizations do |t|
t.column :name, :string, :null => false
t.column :description, :string
So, for instance, if I want an organization called “Us”, i might do:
Organization.new( :name => ‘Us’ ).save!
This works ok for now, but I’m realizing that it couples the migration
to the ‘current’ version of the model class. For instance, if I later
make description mandatory, and validate that (validates_presence_of),
this migration will cease to work. That means that a new developer
won’t be able to get the database by running the migration, because
the migration will complain that the organization does not have a
So – does that mean I should do all data migrations using SQL
statements? How are other people approaching this?