The migration had to run at midnight. At 12:01, every record in production would need a new column.
Adding a new column is simple in theory. It’s one SQL command. In practice, it can break everything. Table locks can stall requests. Schema changes on large datasets can take hours. Migrations can fail halfway, leaving your data in an inconsistent state.
To add a new column safely, start by examining the table size and query load. For large tables, avoid blocking DDL if your database engine supports online schema changes. In MySQL, use ALTER TABLE ... ALGORITHM=INPLACE or ALGORITHM=INSTANT when possible. In PostgreSQL, adding a nullable column with a default can trigger a full table rewrite unless the default is set in a separate step.
Plan for zero-downtime if your system is live. Add columns in a way that’s backward-compatible. First, create the column without default data. Then roll out code that can handle both old and new schemas. Populate the column in batches to avoid I/O spikes. Once every row has the required data, enforce constraints and defaults.