Adding a new column should be simple. In practice, it’s often where things break. Schema changes touch data integrity, migrations, application logic, and deployment pipelines. If you do it wrong, you risk downtime or data loss. If you do it right, it disappears into the flow of development.
The SQL is the easy part:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But real production environments demand more. You need to plan for default values, nullability, indexing, and backward compatibility. A new column can cascade into code updates for ORM mappings, API responses, and caching layers.
For zero-downtime deployments, you may need a two-step migration. First, add the new column as nullable. Deploy the code that writes to it. Backfill data in small, controlled batches to avoid locking the table. Only when the column is fully populated and read everywhere should you enforce constraints or set it non-nullable.
Indexing a new column can speed queries but degrade writes. Benchmark before creation. In high-throughput databases, consider partial indexes or covering indexes to reduce overhead.