Closed kronn closed 6 years ago
Hey @kronn - the issue for the add_column
case is that ActiveRecord wraps each migration in one big DDL transaction. Even if we split apart into the suggested statements, if they all run in the same DDL transaction then splitting them has no effect. It will lock the table just like it does when we call add_column
with the :default
option.
By splitting these statements into separate migrations, each transaction is committed before moving onto the next one. This way the column can be added quickly without holding up the transaction and locking the table while thousands of existing records are updated with the new column default.
I like your suggestion for using say_with_time
for the batches output, I'll leave this issue open until we make that change. Thanks for the feedback!
I see that you recommend splitting one (potentially unsafe) change over several migrations, in the case of
ZeroDowntimeMigrations::Validation::AddColumn
.I think it would be just as good to have the change just split into the suggested statements. This would leave just one point of truth for the change and also make rollback easier as a consequence.
Also, I would suggest to use
say
or even bettersay_with_time
for thefind_in_batches
-output.What are your thoughts on this?