Database Migration Language
5 exercises — practise the English vocabulary for database migrations: up/down migration functions, zero-downtime strategies, backfilling, breaking vs. non-breaking changes, and communicating migration risk in pull requests.
0 / 5 completed
1 / 5
A code reviewer sees a migration file containing both an up() and a down() function. What is the purpose of the down() function, and why do some teams argue it is not always worth maintaining?
Migration up/down vocabulary:
Option B is correct. The
Why down() is controversial:
Option B is correct. The
down() function is intended to undo the up() migration — enabling rollback — but its value is frequently debated in engineering teams.Why down() is controversial:
- Destructive migrations — if
up()drops a column,down()can recreate the column structure, but the data is already gone. The rollback function creates a false sense of safety. - Data migrations — if
up()transforms data (e.g., splits a name column into first_name/last_name), reversing that transformation requires preserving the original, which adds complexity. - Skipped in practice — many teams argue that forward-only migrations paired with a well-tested rollback deployment procedure are safer than relying on
down().
| Function | Direction | Triggered by |
|---|---|---|
up() | Forward — applies the schema change | migrate up / deploy |
down() | Reverse — undoes the schema change | migrate rollback |