Adding a new column in modern systems is not just an ALTER TABLE command. It is a decision that touches performance, deploy safety, rollback plans, and data integrity. Understanding when and how to add a new column without downtime is critical.
The basic steps are simple:
- Write a migration that adds the column with a sensible default or allows NULLs.
- Deploy this migration separately from the code that depends on it.
- Backfill data in batches if the table is large.
- Switch application logic to read and write the new column once the backfill is complete.
- Remove any conditional paths after verifying all reads use the new structure.
On high-traffic systems, the ALTER TABLE step can lock writes. To avoid this, use online schema change tools like gh-ost or pt-online-schema-change. These tools create a copy of the table with the new column, sync changes, and switch over with minimal lock time.