The table was wrong. The data told the truth, but the schema could not keep up. You needed a new column.
Adding a new column is one of the most common schema changes in production databases. It should be simple. It often isn’t. Done wrong, it locks tables, stalls queries, and breaks downstream systems. Done right, it is fast, safe, and invisible to users.
Before you add a new column, understand the scope. Check every service, job, or query that touches the table. Map dependencies. Without this step, you risk deployment failures or data corruption.
In SQL, adding a new column depends on your database platform:
- PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMPTZ; - MySQL:
ALTER TABLE users ADD COLUMN last_login DATETIME; - SQLite:
ALTER TABLE users ADD COLUMN last_login TEXT;
In large datasets, adding columns can lock writes. Use online schema change tools like gh-ost or pt-online-schema-change for MySQL, or pg_online_schema_change for Postgres. Deploy in off-peak hours when possible.