Don't use migrations to seed default data

Updated . Posted . Visible to the public. Deprecated.

It's OK to add data in a migration if your test suite cleans the database before it starts.

For instance, in RSpec:

config.before(:suite) do
  DatabaseCleaner.clean_with(:deletion)
end

Don't insert table rows in a Rails database migration. This will break tests that expect that database to be empty and cause you all sorts of pain.

If you need a place for default application data, use db/seed.rb Show archive.org snapshot or put a script into lib/scripts. It won't run automatically, so add a chore story to Pivotal Tracker as a reminder.

Henning Koch
Last edit
Deleted user #6070
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-11-25 13:33)