Adding a new column to a database sounds simple. It is not. The wrong approach causes downtime, locks rows, or even corrupts data under heavy load. The right approach scales cleanly, preserves integrity, and deploys without blocking writes.
First, choose the right migration strategy. For small datasets, an ALTER TABLE ADD COLUMN might be enough. For production systems with millions of rows, avoid blocking operations. Use an online schema change tool like gh-ost or pt-online-schema-change to add columns without locking the entire table.
Define defaults carefully. Setting a non-null column with a default at creation time will rewrite your whole table in most databases. Instead, create the column as nullable, backfill in controlled batches, then add constraints once data is in place.
Index only when required. Adding an index to a new column can be more expensive than the column itself. Batch index creation or use partial indexes if queries hit specific conditions.