The database groaned. You needed a new column, and every second of delay risked breaking production.
A new column sounds simple. In practice, it can mean schema migrations, locking tables, and possible downtime. The wrong approach can stall queries, block writes, or even corrupt data. The right approach keeps systems responsive and users unaware anything changed.
Start with the schema. Define the new column with explicit types and constraints. Avoid NULL defaults unless intentional; silent nulls can mask bugs. For large tables, adding a column can trigger a full table rewrite. In PostgreSQL, adding a column with a constant default before version 11 rewrites the whole table. In MySQL, depending on storage engine, this may block writes. Study your database’s version-specific behavior before deployment.
Plan the migration in phases. First, deploy the new column as nullable and without defaults to avoid locks. Then run a backfill process in small batches, updating rows without saturating I/O. Monitor replication lag if you run replicas. After the backfill, enforce NOT NULL or add constraints in a final migration.