Adding a new column in a production database is simple in theory, but the wrong approach can block writes, lock tables, and slow every request. Done right, it can be invisible to users while preserving data integrity and performance.
First, define the column’s purpose with absolute clarity. Is it nullable? Does it have a default value? Will it be indexed? These decisions affect migration time, storage, and query speed. Adding a non-null column with a default can cause a full table rewrite in some databases. In systems like PostgreSQL, this can lead to massive locks on large tables.
For low-impact migrations, run schema changes in multiple steps. Add the column as nullable. Deploy. Backfill the data in small batches to avoid saturation of CPU and I/O. Once populated, enforce constraints and update schema definitions in code.