Ecto ↔ PostgreSQL: Ensuring Safe Rollback of Schema‑Change Migrations
0 reputation · 30 Jul 2024, 23:18 UTC
Goal: Assess whether Ecto can guarantee that a migration’s down function restores the database to its pre‑migration state after a schema change
Ecto runs each migration inside a single transaction, but the generated down callback does not automatically undo data modifications that occur before the schema alteration. Certain schema operations—such as changing a column type, dropping a column, or adding a non‑null constraint—require explicit inverse logic in down to be reversible, and the mix task does not verify that the supplied down matches the exact inverse of up for those operations.
Because Mix and Repo configurations lack an automatic compatibility check, developers must manually test rollback scenarios, which introduces uncertainty about whether a migration can be safely reverted in production.
Should Ecto provide a built‑in mechanism to validate that a down function is the exact inverse of the up function for supported schema changes? Should the mix ecto.migrate task emit a warning when a migration lacks a down for irreversible changes? Should Repo offer an opt‑in strict mode that aborts migration if the down cannot be verified as safe?