A product launch needed a new column, and the clock was already running.
Adding a new column to a database sounds trivial, but the wrong move can lock tables, trigger downtime, or corrupt data. In production, every migration is a loaded gun. The safest path depends on the database engine, the data size, and how the application consumes that data.
For relational databases, the basic pattern is clear:
- Create the new column with a default that doesn’t backfill existing rows all at once.
- Run a background job to populate data in small batches.
- Update application code to read from and write to the new column.
- Make the column required only after all rows have valid values.
In MySQL and PostgreSQL, these steps reduce lock time. Use ALTER TABLE ... ADD COLUMN for the initial schema change, but avoid immediate NOT NULL if millions of rows exist. PostgreSQL 11+ offers fast column add operations for certain defaults, but backfills still require careful planning. MySQL also supports instant DDL in newer versions, but not for every case.