How can I add a non-null column with a default using Doctrine Migrations without causing downtime?
0 reputation · 27 Mar 2024, 03:12 UTC
I need to modify the schema of a small application that must stay online, and I want to use Doctrine Migrations to perform the change.
The table contains a moderate amount of data, and I cannot afford a long lock that would block reads or writes. I am unsure which sequence of migration steps—adding the column as nullable, deploying updated code, backfilling existing rows, and then making the column non-null—will keep the application available, especially when specifying a default value.
What is the safest order of Doctrine migration operations to add a non-null column with a default? How should I handle the default value during the migration to avoid table locks? Are there any Doctrine-specific options or flags that minimize locking during the schema change?