The migration ran without errors, but the data wasn’t right. The fix was a new column.
Adding a new column sounds simple. In production, it is not. Schema changes are high-risk. Downtime, locks, and triggered rebuilds can break everything. A single ALTER TABLE can freeze writes if the table is large enough. This is why careful planning for new column creation is critical.
The safest approach depends on the database. In PostgreSQL, adding a nullable column without a default is fast because it only updates the catalog. MySQL supports instant column additions in recent versions, but older ones rewrite the entire table. When a default value is needed, set it in application logic first, backfill in small batches, and then enforce it at the database level.
For high-traffic environments, create the new column in a way that does not block reads or writes. Use online schema change tools like gh-ost or pt-online-schema-change for MySQL. In PostgreSQL, run the migration in off-peak hours or during rolling deploys. Always verify that indexes and constraints on the new column are added in separate, small steps to reduce lock times.