Adding a new column is one of the most common schema migrations. Simple in theory, but in production it can stall deployments, lock tables, and break code if handled without care. The key is speed, safety, and zero downtime.
First, define the new column with the correct type and default values. Explicit is better than implicit. Avoid NULL unless it’s intentional. For large datasets, adding a column with a default that requires rewriting the entire table can be dangerous. Use a nullable column first, backfill in batches, then add constraints once the data is complete.
Second, ensure your application code is aware of the column before you backfill. Deploy code that can handle both states: data existing and data missing. Feature flags can help toggle read/write logic during migration phases. This prevents runtime errors when your schema and code versions don’t sync.