Does anyone test that migration rollbacks actually preserve data (not just exit 0)? #1817
Unanswered
croc100
asked this question in
Usage Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
One failure mode that's bitten me a few times: alembic downgrade exits 0,
no exceptions, CI goes green — but rows are silently gone. The column came
back in downgrade(); the data didn't.
The usual setup (upgrade → downgrade → check exit codes) doesn't catch this
because the SQL is valid. The schema is correct. The data is just missing.
I ended up building a pytest plugin to catch it: pytest-mrt. It seeds rows
before each migration, runs downgrade, and asserts the data survived. Also
does static analysis for the obvious patterns (drop_column in upgrade,
no-op downgrade, PostgreSQL ENUM adds that can't be rolled back, etc.)
without needing a database at all.
Curious if others have run into this class of bug and how you're handling it.
Any patterns that aren't on the list yet would be good to know about:
https://croc100.github.io/pytest-mrt/patterns/
GitHub: https://github.com/croc100/pytest-mrt
Beta Was this translation helpful? Give feedback.
All reactions