The migration finished at midnight, but the schema wasn’t ready. You needed a new column, and the system refused to wait.
Adding a new column sounds simple. In practice, it can bring down production if done carelessly. Schema changes touch every layer: database locks, application logic, tests, and deployments. The key is to add the column without breaking the queries, avoiding full table rewrites, and keeping zero downtime.
The safest approach is an additive change. First, create the new column with a default that does not force a rewrite. Avoid NOT NULL constraints at creation. Let it be nullable, and backfill data in batches to control load. Use feature flags to switch reads and writes to the new column, and check query plans before enabling constraints.
For large datasets, online schema change tools can handle the migration without blocking. MySQL users often reach for pt-online-schema-change or gh-ost. PostgreSQL can add columns instantly in most cases, but setting defaults can still cause table rewrites. Always test in a replica or staging environment to catch hidden locks.