Adding a new column sounds simple, but it can trigger downtime, data mismatches, or degraded performance if done carelessly. In production systems, a schema migration is not just about ALTER TABLE. It’s about control over both data and code paths during deployment.
The safest way to add a new column is with a zero-downtime migration. First, add the column in a backward-compatible way. Make it nullable or set a default. Do not remove or rename anything in this step. Deploy the code that begins to write to the new column, but still reads from the old one until writes are confirmed. Only after that do you migrate data across or switch reads. Finally, clean up the old column in a separate migration.
For large datasets, always consider the size of the table and the locking strategy of your database engine. Online schema changes, batched data backfills, and index creation on the new column should each be separate controlled steps. Monitor query performance after each change.