Adding a new column is more than appending data. It changes schema, affects queries, and touches every part of the stack that interacts with the database. Done wrong, it causes downtime. Done right, it’s invisible to users.
Start with the schema migration. In SQL, ALTER TABLE is the core command. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This runs fast on small tables. On large tables, the operation can lock writes. To avoid service impact, use online schema changes or phased rollouts. Tools like pt-online-schema-change or gh-ost handle high-traffic databases without blocking queries.
Next, update application code. Treat the new column as optional until populated. Null-safe reads prevent runtime errors. Migrations should include backfilling scripts where necessary, executed in batches to reduce load.