The table was wrong, and you knew it the moment you saw the data. A missing field. Another team’s query breaking. The schema needed a new column, and you had to add it without taking the system down.
Adding a new column sounds trivial until you do it on a live production database with millions of rows. The wrong approach locks tables, kills performance, and burns your maintenance window before the migration is halfway done.
Choose the right ALTER TABLE strategy. On small datasets, a direct schema change works. For large tables, avoid blocking writes. Use an online migration tool like pt-online-schema-change for MySQL or ALTER TABLE ... ADD COLUMN with ONLINE = ON in newer versions. PostgreSQL is faster for ADD COLUMN without a default, but adding a default with a rewrite is expensive. Break it into two steps: add the nullable column first, then backfill in controlled batches.