Adding a new column is one of the most common schema changes in software. It sounds simple, but it can break production if done without care. Good teams treat it as a controlled operation. The wrong approach slows deploys, locks tables, and causes outages.
To create a new column safely, start with clarity on intent. Define the exact name, type, and nullability. Use a reversible migration script. Test it in a replica or staging environment with realistic data size. For large tables, use an online schema change tool or an incremental approach to avoid blocking reads and writes. Keep migrations atomic when possible, but for very large datasets, split them into additive and backfill phases.
In SQL, adding a column is straightforward:
ALTER TABLE users ADD COLUMN last_seen TIMESTAMP NULL;
But that’s not the whole story. If the new column has a default or a not-null constraint, the change can rewrite the whole table. For large, busy systems this is dangerous. Instead, first add it as nullable with no default. Then backfill data in small batches. Once complete, enforce the constraint.