The table was fast, but the requirements changed. A new column had to be added, and it had to happen without breaking production.
Adding a new column sounds simple. In practice, it’s a high‑risk change if the database holds millions of rows or runs under constant load. The wrong approach can lock tables, stall queries, or trigger downtime. The right approach keeps traffic flowing and data safe.
In SQL, adding a column is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
But execution matters. On PostgreSQL, this is instant if the column allows NULL and has no default. On MySQL, older versions may rewrite the table. Always check the version and engine before running ALTER TABLE in production.
For schema migrations, break the change into steps. First, add the new column with a NULL default. This avoids large rewrites. Then backfill data in small batches to prevent contention. Finally, add constraints or indexes.