The migration left one broken test, and the root cause was clear: a missing new column.
Adding a new column is not just a schema change. It shifts the structure of your data and can impact every query, index, and dependency that touches the table. Done wrong, it breaks production. Done right, it ships with zero downtime.
Start with the design. Decide the exact name, type, and constraints before writing any code. Keep naming consistent and avoid nullable columns unless necessary. Plan defaults carefully—empty fields can cascade into logic errors.
For relational databases, write a migration script that adds the new column in an idempotent way. In PostgreSQL and MySQL, ALTER TABLE is the core command, but be aware of locks. Online schema changes or phased rollouts can prevent blocking queries.
Always backfill data in controlled batches. This step is critical. Without it, the new column might be technically present but functionally useless until fully populated. Test backfilled values against existing data paths.