The migration hit production at 03:17, and the app went dark.
The error was clear. The schema expected a field that didn’t exist. The missing piece? A new column.
Adding a new column to a database table looks simple. It isn’t. Every choice you make—data type, nullability, default values—can cause downtime or corrupt data if done wrong. In high-traffic systems, a blocking migration can freeze writes, queue requests, and break the application layer.
The safest way to add a new column is online, without locking critical paths. In PostgreSQL, some column additions are instant if there’s no default and the column is nullable. In MySQL, online DDL can avoid full table copies if configured correctly. Always measure the impact in a staging environment with production-like data before touching live systems.
Backfill strategies matter. For a non-nullable column, add it as nullable first, deploy, then backfill in batches. After data is complete, change constraints in a separate migration. This reduces table-wide locks and keeps deployments atomic.