Adding a new column sounds simple. It is not. In a live system, schema changes must be precise, fast, and safe. One wrong ALTER TABLE can lock writes, drop indexes, or cascade into downtime. The only way to move fast without chaos is to design migration steps that minimize lock times and keep old code running until the new column is in place and populated.
The process starts with inspection. Check exact table size. Identify primary keys, indexes, and concurrent access patterns. Then design the migration:
- Create the new column in a non-blocking way where possible.
- Backfill data in batches to avoid I/O spikes.
- Keep the old column or logic until all dependent code paths are changed.
- Run deployments and schema changes in separate, reversible steps.
For PostgreSQL, use ALTER TABLE ADD COLUMN for lightweight additions, but plan for long-running migrations by running them during low load or with concurrent-safe methods. In MySQL, watch for table copy behavior in older versions and use pt-online-schema-change when needed.