Adding a new column sounds simple. In practice, it can break production, stall deployments, and leave teams fighting hidden performance issues. The key is to design the change for zero downtime and predictable behavior.
First, define the column clearly in the migration. Specify the data type, default value, and constraints. Avoid adding NOT NULL columns without defaults; they stop the migration cold on large tables.
Second, stage the deployment. In relational databases like PostgreSQL or MySQL, modifying the schema locks tables. Use incremental changes:
- Add the column with a safe default or nullable setting.
- Backfill data in batches.
- Enforce constraints and indexes after the data is ready.
Third, keep indexes minimal during the initial add. Index creation is expensive. Build them after the backfill completes to prevent locking or replication lag.