The migration script fails halfway through. You scan the logs. The problem is obvious: the table is missing a new column.
Adding a new column sounds simple, but schema changes in production require precision. You must consider database locks, downtime, data consistency, and backward compatibility. A careless ALTER TABLE can freeze traffic or corrupt state.
When introducing a new column in SQL, the safest approach is to plan the change in stages. First, add the column as nullable with a default value. This ensures the schema update runs quickly and avoids blocking queries for long periods. Then backfill data in small batches to reduce load. Only after the backfill is complete should you add constraints or make the column non-null.
For PostgreSQL, use ALTER TABLE ... ADD COLUMN with care. Large tables can lock writes during metadata changes. Adding a column with a constant default in newer Postgres versions is fast, but on older versions it rewrites the whole table. MySQL and MariaDB have similar considerations, with different performance characteristics depending on storage engine and version.