The migration broke at 2:14 a.m. The logs showed a missing column. The fix was simple: add a new column. But the stakes were high, and every second mattered.
A new column in a database is more than schema. It’s a contract update between your code, your data, and your future. Done right, it’s painless and invisible. Done wrong, it can lock tables, block writes, or corrupt production.
Before adding a new column, decide on type, default value, nullability, and indexing. Use migrations that are backward compatible. Deploy in stages: first add the nullable column with no constraints, then backfill data, then enforce rules. This sequence avoids downtime and breaking queries in other services.
In PostgreSQL, ALTER TABLE ADD COLUMN is straightforward, but large tables need caution. With MySQL, adding a column may require a table copy depending on storage engine. In both cases, online schema change tools can reduce locking risk.