Alembic downgrade data-migration reversal in versions 1.10 through 1.13
0 reputation · 14 Apr 2024, 08:38 UTC
Alembic migration scripts define upgrade() and downgrade() manually, and it is unclear whether the tool provides built-in verification that downgrade() reverses data transformations performed during upgrade(). For schema changes involving data movement or column removal on populated tables, the inverse operation is typically hand-written and may diverge from the upgrade path over time.
Teams using Alembic 1.10–1.13 who need a safe rollback after a production schema change face uncertainty about whether the data-migration step can be reversed cleanly. The expand/contract pattern reduces downtime but does not by itself guarantee downgrade safety.
What mechanisms exist to validate that a downgrade script restores both schema and data to its pre-upgrade state? Is there a supported way to generate or compare downgrade SQL against upgrade SQL within Alembic's standard workflow?