I have and ORM app that uses SQLAlchemy, Alembic for migration and Pytest for testing. In my testing, I have a database as a fixture. It used to be, before I used migrations, that I dropped all the tables and recreated them for each testing session.
Now that I am using migrations, I want to use Alembic in creating my fixtures too because I believe that mimics a production environment more closely.(Is that a good rationale?)
One way to do it is to downgrade()
all the way down and upgrade()
up each time. I don't really like this. I might be wrong.
Another would be to drop_all()
and create_all()
for unit tests, and just write another test that stamps the database with head and tests an upgrade
and downgrade
.
Is there another good/standard way to integrate migrations with fixtures so I do not have to use drop_tables
?
Or is there a way to, after drop_tables
stamp the db as "tail" or empty? without explicitly using the migration hash for revision 0, cause that creates dependencies, something like alembic downgrade -1
that will make it go back to year 0. Thank you.