The migration failed because the schema didn’t match. You check the logs. The problem is clear: you need a new column.
Adding a new column should be simple, but in production it’s never just an ALTER TABLE and done. You have to think about downtime, locking, data backfill, indexing, and how changes propagate through services. A single error can block requests, corrupt data, or break downstream jobs.
The fastest way to add a new column without risk is to plan in three steps:
- Create the new column without constraints. This makes the schema change fast and non-blocking.
- Deploy application code that writes to both old and new columns. This stage ensures new data lands in both places and gives you room for backfill.
- Backfill data in small batches. Avoid long locks by processing slices of rows. When it’s done, switch reads to the new column and drop the old one if needed.
For large databases, use online schema change tools like pt-online-schema-change or native features like PostgreSQL’s ADD COLUMN with DEFAULT handling. Watch query plans. Adding indexes at the wrong time can stall traffic.