Adding a new column to a production database should be simple. In practice, it’s where mistakes get expensive. Migrations can lock tables, slow queries, or even break critical paths. The right approach is one that makes the change atomic, testable, and reversible.
First, write a migration that adds the new column without modifying existing data. Use NULL as the default if you must, but better yet, allow for no default and update values in a separate step. This avoids long locks and keeps the schema change lightweight.
Next, backfill the data in batches. This ensures you don’t overwhelm the database or blow through maintenance windows. Monitor row counts and timing. If your system supports it, run the job in parallel across shards.