Closed kronn closed 7 years ago
Indexes should always live in their own migrations with the DDL transaction disabled so that they can be added concurrently. Other types of schema or data migrations should not be mixed with index changes since the transaction is disabled.
Data migrations are much more error prone than schema changes in our experience. They also tend to take a longer to run than migrations that only change table schemas. For these reasons we've opted to run our data changes in their own dedicated migrations to make debugging and rollbacks easier if any issues arise.
Currently we detect "data migrations" by using this ActiveRecord::Base patch. If any ActiveRecord::Base
object is initialized while the migration is running then it is classified as a "data migration".
It's a little bit more developer overhead to split migrations into logical groups like this but it's bitten us enough times now that we'd rather be safe than sorry.
I strongly disagree with the error-message of
ZeroDowntimeMigrations::Validation::MixedMigration
. I see the problem more with using ActiveRecord-models in migrations in the first place.How do you determine if a migration is data-migration?