Adding a new column sounds simple. It isn’t. Done wrong, it can lock your database, stall your app, and drop queries to their knees. Done right, it’s invisible—fast, safe, and production-proof.
First, choose the right migration strategy. On small datasets, adding a new column with ALTER TABLE is fine. On large, high-traffic tables, that approach risks downtime. Use a non-blocking migration tool that rewrites the table in the background, such as pt-online-schema-change or gh-ost. These let you add your new column without locking reads and writes.
Next, set constraints and defaults with care. Adding NOT NULL with a default can rewrite the full table, increasing migration time. In many cases, it’s better to add the column as nullable, backfill data in batches, then apply the constraint.
Index only when necessary. Creating an index with the new column during the same migration can compound load. Add indexes after the column is deployed and populated. This splits the risk and makes rollback simpler.