The query had been running fine for months. Then the spec changed. Now the database needs a new column, and the next deploy is hours away.
Adding a new column can be simple, or it can shatter production if done without care. Schema changes ripple through the stack—migrations, application code, cache layers, monitoring. To get it right, you need a plan.
First, define the column precisely. Pick the correct data type and constraints. Avoid nullability changes later—they are expensive. Name the column with intent; schema clarity prevents long-term confusion.
Second, design the migration. For small tables, a direct ALTER TABLE ADD COLUMN works. For large datasets, break the operation into steps: add the column without defaults, backfill data in batches, then apply constraints. This prevents table locks and downtime.