The migration script fails. Production locks. You need a new column fast.
Adding a new column to a database sounds simple, but speed and correctness decide whether it’s surgical or catastrophic. Schema changes shape performance, resilience, and how teams deliver features without downtime. The wrong approach can block queries for minutes—or hours—on busy systems.
Start with precision. Always know the data type before touching the table. Choose the smallest type that works today and will work in five years. Map constraints early: NOT NULL columns need defaults or staged backfills to avoid write failures.
On large tables, use an online schema change. In MySQL, tools like gh-ost or pt-online-schema-change create a shadow table and replay changes in real time. In PostgreSQL, certain ALTER TABLE ADD COLUMN operations are fast if you keep defaults nullable, then backfill in controlled batches. Avoid adding indexes until the data is populated unless the migration plan accounts for the extra load.