Avoid using Rails models in migration.
- Models might have some
lifecycle callbackswhich we dont want to be invoked in a migration.
- As we know what we are doing we dont want to deal with
- Model names can change irrespective of db table.
- Try to use
raw sqlas close as possible.
Squash them after a period of time.
- To my experience over a period of time these migration files are painful and useless.
rake db:migratemight take a few seconds, or creating of a new database might take a few minutes when these files are big. Consider using tools like squasher.
Make them irreversible.
In Production it makes sense to have IrreversibleMigration as the code is tested in lower environments. If there is an issue try to fix it with a follow up migration.
Note: If there is a new developer in your team and setting up their environment. Let them do `rake db:schema:load` to get latest db copy.