The migration was hours away when the need for a new column landed on your desk. No buffer, no rollback plan—just the requirement and a production database that couldn’t afford downtime.
Adding a new column sounds simple until you factor in table size, replication lag, and schema drift. The wrong ALTER TABLE can lock writes for minutes or crash critical paths. The right approach creates the column safely, backfills data without throttling performance, and deploys without blocking queries.
Modern databases handle this differently. PostgreSQL supports ADD COLUMN with a default in certain versions without table rewrites. MySQL and MariaDB may still rewrite large tables unless you use tools like pt-online-schema-change or gh-ost. Column order is mostly cosmetic but can impact migrations if your ORM or legacy code depends on positional queries.
For zero-downtime changes, add the new column as NULL first. Backfill in batches, using small transactions within a migration framework or with raw scripts in an operations pipeline. Once data is in place, add constraints and defaults in follow-up migrations. This keeps locks short and predictable.