The migration script runs. One wrong command and the main table locks. You need a new column, but you cannot afford downtime.
Adding a new column sounds simple. In practice, it tests your control over schema migrations, indexing strategy, and data consistency. The choice between ALTER TABLE and creating a shadow table can decide performance under load.
Understanding the New Column Impact
When you run ALTER TABLE ADD COLUMN, your database engine may rewrite the entire table. On small datasets, this is invisible. On large tables with high concurrency, it can freeze critical operations. Always test in a staging environment with production-level data volume.
Default Values and NULL Safety
Defining a new column without defaults can break queries expecting non-null data. Adding a DEFAULT value ensures inserts remain predictable. Avoid backfilling in a single transaction—batch updates reduce lock contention.