The query came back with an error, and the reason was clear: the table needed a new column.
Adding a new column sounds simple. It isn’t — not if you care about uptime, data integrity, and query performance. The wrong migration locks rows, slows writes, or blocks reads. On a production database, that’s a risk you only take once.
To add a new column safely, start by defining exactly what must change. Schema drift destroys stability. Use precise naming. Decide on the type, constraints, and default values before you run a migration. For large datasets, consider adding the column without defaults first, then backfilling in batches to avoid long-running locks.
In PostgreSQL, ALTER TABLE ADD COLUMN is fast for empty defaults and nullable fields, but slow if you set a non-null default inline. In MySQL, altering a column can rebuild the entire table unless your engine supports instant DDL. On cloud-managed databases, check for feature flags like Postgres’ NOT VALID constraints or MySQL’s ALGORITHM=INSTANT.