The migration failed five minutes before launch because the database was missing a new column.
Adding a new column sounds simple. It isn’t—at scale it can stall deployments, lock tables, and cause inconsistent reads. The right approach depends on the database engine, table size, and uptime requirements. Knowing which pattern to use can mean the difference between shipping on time and a rollback.
In PostgreSQL, ALTER TABLE ADD COLUMN runs fast when the column has no default or when the default is NULL. Adding a default with a non-null value rewrites the table, which can be slow on large datasets. Instead, add the column without the default, then run an UPDATE in batches, and finally set the default.
In MySQL, adding a new column to an InnoDB table may lock writes. Use ALGORITHM=INPLACE or ALGORITHM=INSTANT with newer versions to avoid downtime. For older versions or massive tables, online schema change tools like gh-ost or pt-online-schema-change can help.