Adding a new column sounds simple. In production, it can break queries, stall deployments, and lock tables. The goal is to ship fast without downtime or data loss. That means planning the migration, understanding the impact on indexes, and keeping the application consistent while the schema changes.
Start with the type and constraints. Decide if the new column is nullable or requires a default. A non-null column with no default will fail if existing rows lack values. Even if it works locally, production datasets are larger, slower, and more dangerous.
Consider the order of operations. In many databases, ALTER TABLE can be blocking. For large datasets, use an additive change pattern:
- Add the new column as nullable.
- Backfill data in small batches.
- Add constraints or defaults only after the backfill is complete.
If the new column is part of a hot path query, update indexes deliberately. Adding the column to an index can triple storage use during creation. Test the query plan before and after. Every write might now carry extra cost.