Adding a new column should not be slow or risky. Schema changes can lock rows, block writes, or take entire systems offline. The goal is precision: alter the database to add the new column with zero downtime, zero surprises.
In most SQL databases, the basic command is simple:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works, but on large datasets, it can fail under production load. The better approach is a two-step migration. First, create the new column as nullable to avoid rewriting every existing row. Second, backfill data in small batches, monitoring query performance. Finally, mark the column as non-null if required.
For Postgres, adding a nullable column is fast because it updates metadata only:
ALTER TABLE orders ADD COLUMN status TEXT;
No full table rewrite, no downtime. Then, run a batch update: