The fix was simple: add a new column. The hard part was doing it without downtime, without corrupting data, without breaking the code that depended on the old shape of the schema.
A NEW COLUMN isn’t just a schema change. It’s a contract update between the database and every service that touches it. Add it badly and you get production errors, rollback headaches, and sleepless nights. Add it right and it fades into the background—no one notices except the audit logs.
First, decide if the column can be nullable or needs a default value. Nullability changes the migration plan. A non-null column on a large table can lock writes and block queries. Use phased deployments:
- Create the new column with a safe default or allow nulls.
- Backfill in batches to avoid performance hits.
- Deploy code that writes to both old and new columns if you’re deprecating existing fields.
- Switch reads to the new column only after full backfill verification.
On most SQL databases, ALTER TABLE is enough for small datasets. For high-traffic systems, use tools like pt-online-schema-change or gh-ost to run the migration online. Combine these with feature flags to control rollout at the application layer.