Adding a new column sounds simple. It isn’t. It touches schema, migrations, indexes, queries, and downstream code. Get it wrong, and you can lock a table, slow a critical path, or break prod.
First, decide if the new column belongs in the current table. Check normalization. Check data type. Choose the smallest type that fits the known range. Avoid NULL if possible; defaults make migrations safer.
In relational databases, adding a new column is a DDL operation. In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast if the column is nullable with no default. If you need a default, add the column first, then update rows in chunks, then set the default. This avoids full table rewrites. In MySQL, column order can matter for some tools, but not for performance.
Plan the migration. In production, use incremental releases:
- Add the new column with a safe default.
- Backfill data in small batches with indexed filters.
- Deploy code that reads from the new column while still supporting old logic.
- Migrate writes.
- Remove fallback logic.
Check indexes. If the new column is part of a query filter or join key, add the index after backfill to reduce write load during migration. Use partial indexes when possible.