The migration script failed at 2 a.m., and the logs pointed to one missing change: a new column.
Adding a new column sounds simple, but in production, it’s where schema changes meet downtime risk. Whether you’re working with PostgreSQL, MySQL, or SQLite, the wrong approach can lock tables, cause replication delays, or break application code. The key is to integrate the new column with zero interruption to live traffic.
Start by defining the column in a non-blocking way. In PostgreSQL, ALTER TABLE ... ADD COLUMN without a default value can be instantaneous, while adding a default can trigger a costly rewrite. For MySQL, ALGORITHM=INPLACE reduces lock time. Always stage your column addition before backfilling data at scale.
Once the column exists, update your codebase to read from and write to it without switching behavior until both schema and data are aligned. This can mean writing to both the old and new columns, then cutting over in a second deployment. Feature flags help control the rollout.