Read more

Don't use migrations to seed default data

Henning Koch
November 25, 2010Software engineer at makandra GmbH

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.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Henning Koch to makandra dev (2010-11-25 14:33)