Adding a new column to a table should be simple, fast, and precise. In production systems, the impact of schema changes can be brutal if not handled with care. The goal is zero downtime, no data loss, and no surprises in query performance.
First, define the purpose of the new column. Decide if it stores persistent data, cached values, or computed results. Pick the data type with intent. Smaller types save space, speed up queries, and reduce index size. Always make nullability explicit—default choices hide silent bugs.
In SQL, you use an ALTER TABLE statement:
ALTER TABLE users ADD COLUMN last_seen TIMESTAMP WITH TIME ZONE DEFAULT NOW();
For large tables, this can lock reads and writes. The fix is an online migration strategy. Use tools like pt-online-schema-change or gh-ost to add columns without halting traffic. Partitioning, sharding, or creating a shadow table can further reduce migration risk.