The migration broke at 2:17 a.m. because the schema was missing one thing: a new column.
Adding a new column to a production database is simple in theory and dangerous in practice. The process touches data integrity, query performance, and uptime. A careless alter table can lock rows, block writes, or spike CPU until the cache evicts half its working set. Modern systems demand a precise, tested approach.
First, define the purpose of the new column. Decide its data type, nullability, and default value. Think about indexing now, not later. A poorly chosen type or missing index can cause silent performance drops.
Second, choose a deployment strategy. In PostgreSQL, ALTER TABLE ... ADD COLUMN is straightforward for small datasets, but on large tables it can be a long lock. In MySQL, some versions still rebuild the entire table for a new column. Use online schema change tools—like gh-ost or pt-online-schema-change—to reduce downtime.