The migration was almost done when the database broke. A missing new column stopped every process cold. Error logs filled the screen. Transactions failed in seconds.
A new column is one of the most common schema changes in any database. It sounds simple: ALTER TABLE ADD COLUMN. But adding it in production without downtime, data loss, or inconsistent state takes precision. Each step matters.
First, define the column type exactly. Mismatched types lead to silent failure or broken constraints later. Decide if the column should allow NULL or require a default value at creation. This choice impacts table rewrite cost and lock time.
Second, consider indexing. Adding an index at the same time as the new column can cause a full table lock and block writes. In high-traffic systems, split the operations. Add the column first. Populate it in controlled batches. Then create the index.
Third, handle backfill carefully. For small datasets, one statement may work. For large datasets, use id-based ranges or time-based chunks to avoid long locks. Monitor query performance during the operation to prevent service degradation.