If you have data in your production database that you want to change, you have several options:
- Change it manually with
- Use a migration.
Changing manually is quick but also dirty. This works good for information people entered manually on the production system. If the records were created in a migration, this is a bad choice, because running the migration again may re-create the old versions of the records.
db/seeds.rb is my preferred choice, but you have to be very careful to
write your seed data in an idempotent way, meaning it can handle an empty
database as well as an old version or future versions without overwriting
anything. This usually takes some trial and error and some failed deployments
to get right. I recommend trying this approach locally with a dump of the
Using migrations is a good idea if the change needs to happen on several
machines, for example multiple developers, a staging environment and the
production system. Make sure you do not use any rails models directly as they
may change and be incompatible in the future. I like using plain SQL via
execute "UPDATE table ...". Also make sure your migration works with an empty