Adding a new column sounds simple, but in production databases, it can block writes, lock tables, and trigger cascading failures. The right approach avoids downtime, preserves data integrity, and keeps deployments fast.
First, decide on the column’s purpose and data type before touching the database. For large tables, adding a new column with a default value can lock the table. Instead, create the column without a default, backfill data in small batches, then set the default in a later migration. This pattern reduces lock time from minutes or hours to milliseconds.
Second, make schema changes backward compatible. Deploy code that reads both the old and new column before switching writes. This avoids breaking services running on staggered deploy schedules.
Third, index the new column only if needed. Index creation is often more expensive than adding the column itself. If the column is used in queries immediately, build the index concurrently to prevent blocking.