The migration was almost done when the requirements changed. You needed a new column. Not next week—now.
Adding a new column sounds simple. In most databases, it is. But the real challenge comes when the table is large, traffic is high, and downtime is not an option. Schema changes can block queries, spike CPU, and cause production issues if not planned.
The first step is to decide how the new column will be initialized. If it needs a default value, set it without heavy backfill. For large datasets, avoid locking the table for writes. Use operations that add the column instantly, such as “ADD COLUMN … NULL” in MySQL or PostgreSQL, then backfill in batches.
In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for NULLable columns, but slow for defaults that require rewriting every row. To add a default in a non-blocking way, create the column as NULL, populate it in controlled batches, then alter it to set the default.