The database migration crashed at midnight. Logs showed the schema was clean, but one query kept failing. The problem: a missing new column in the production table.
Adding a new column sounds simple. It rarely is. In PostgreSQL, ALTER TABLE ADD COLUMN triggers table rewrites in certain cases. In MySQL, it can lock writes depending on the storage engine. In distributed systems, schema drift spreads fast if migrations aren’t atomic and reversible.
A robust new column workflow starts with versioned migration scripts. Name them with timestamps. Keep them in source control. Test them against a clone of production data. Run them through continuous integration before deployment.
Data type choice matters. Pick the smallest type that fits the data. If you add a nullable column, remember that NULL scans can hurt performance with some query plans. If you must set a default value for billions of rows, stage it: