In alembic, we have to implement the upgrade
and downgrade
functions, for each migration we add. AFAIK the downgrade
function is suppose to revert all changes made by the upgrade
.
Is there a way to automatically test if the downgrade
function is implemented correctly?
As an end result, I would like to add a pytest test that asserts each migration in that way.
A naive approach would be to implement a function that makes an "inventory" of all schemas, tables, indexes, columns, etc; compares the inventory before the migration and after performing upgrade and downgrade on a given migration; If both inventories are identical, then downgrade
was implemented properly. The problem with this approach is that (i) looks too cumbersome to implement and (ii) seems computationally very expensive.
Is there a better way to implement a test on my downgrade
functions?