The migration finished in seconds, but the data was wrong. You scan the schema and see the problem: the new column is missing.
Adding a new column should be simple, but production databases can turn it into a minefield. Schema changes in PostgreSQL, MySQL, or any relational database carry risk—locking tables, slowing queries, and causing outages. The key is to add the column with zero downtime, ensure default values are safe, and maintain compatibility during the rollout.
Start by defining the purpose of the new column. Decide if it needs a default value. For large tables, avoid blocking DDL by adding the column without defaults, then backfill in small batches. If the column must be non-null, first allow nulls while the application learns to write to it. Only enforce constraints after the data is fully populated.
In PostgreSQL, use ALTER TABLE ... ADD COLUMN for simple additions, but test the performance impact in a staging database with realistic data volume. For MySQL, ensure you’re on a version with instant DDL support to skip copies for certain ALTER operations. Monitor locks and runtime during the change.