Choose between change/0 and explicit up/down migrations for irreversible Ecto schema changes
0 reputation · 14 Oct 2025, 14:30 UTC
Goal: ensure that a failed Ecto upgrade can be recovered safely when a migration contains irreversible operations such as raw SQL or data transforms.
Constraint: the change/0 callback can auto‑reverse only a limited set of commands; any irreversible step raises on rollback, while explicit up/0/down/0 pairs give full control but require more code and duplicate logic. Adapter behavior adds another layer: PostgreSQL wraps DDL in a transaction so a failed change/0 migration rolls back cleanly, whereas MySQL’s non-transactional DDL can leave partial schema artifacts that must be undone manually before a retry.
Uncertainty: which migration style offers a more predictable recovery path when a project mixes reversible schema changes with irreversible data migrations, especially when deploying to adapters with differing transaction guarantees.
- Which style provides clearer rollback semantics for irreversible data transforms?
- How does adapter transactionality affect the safety of each style during a mid‑migration failure?
- When should developers prefer explicit up/down over change/0 despite the additional boilerplate?