The schema was breaking. You needed a new column, and you needed it without locking the database or risking data loss.
Adding a new column sounds simple. In production, it can be risky. Schema changes can block writes, cause long-running migrations, and bring down critical services if done wrong. The safest way to add a new column is to plan for zero downtime and consistent data from the start.
A new column should be defined with the correct type, constraints, and defaults. Avoid backfilling in the same migration that creates the column. First, create the column as nullable. Deploy. Then backfill values in batches. Finally, add the NOT NULL constraint once every record is valid. This three-phase approach avoids locks that freeze traffic.
When adding a new column to large tables, use database-specific online DDL features. PostgreSQL’s ADD COLUMN is fast if the column has no default. MySQL can use ALGORITHM=INPLACE to avoid copying the table. Always test the migration on production-sized replicas to measure the real execution time.