The migration was almost finished when the error hit: missing column. A single absent field stalled the release.
Adding a new column seems trivial. But in production systems with millions of rows, it must be done with precision, speed, and zero downtime. The wrong approach can lock tables, drop indexes, or corrupt data. The right approach treats a schema change as a surgical operation.
A new column begins with definition. Name it clearly, use consistent casing, and avoid reserved words. Choose the correct data type to balance size, performance, and future-proofing. Always set default values deliberately. Null defaults can avoid costly backfills, while non-null defaults can enforce integrity from day one.
Next comes deployment. For large tables, avoid blocking statements. Instead, add the column first, then backfill in controlled batches. Monitor I/O load and replication lag. Coordinate schema changes with application code so reads and writes handle the new field consistently.