The culprit was a missing NEW COLUMN.
Adding a new column is simple when done right. Done wrong, it can lock tables, spike CPU, and cause downtime. This guide shows the fastest, safest way to add a new column in any relational database, from PostgreSQL to MySQL. It focuses on zero-downtime changes, schema evolution, and performance impact.
Plan the schema change
Before adding a NEW COLUMN, decide on its data type, null constraints, and default values. Defaults with backfills on large tables can be dangerous. On production datasets with millions of rows, ALTER TABLE ... ADD COLUMN ... DEFAULT ... will rewrite the entire table in some systems. This can cause hours of blocking.
Use a staged migration
Step one: add the new column as nullable with no default. This is nearly instant. Step two: backfill in small batches with an online job or migration script. Step three: set your NOT NULL constraint after the backfill is complete. This guarantees minimal lock time.
Handle indexes carefully
If the new column needs an index, create it concurrently if your database supports it. In PostgreSQL, use CREATE INDEX CONCURRENTLY; in MySQL, use ALTER TABLE ... ALGORITHM=INPLACE. Always monitor the impact during creation.