Alembic has commands to upgrade and downgrade to a specific revision, e.g. on the command line:
alembic upgrade <target-revision>
And
alembic downgrade <target-revision>
Is there a simple way to migrate to a specific revision if you don't know whether it's an upgrade or a downgrade? i.e.
alembic migrate <target-revision>
I can work out the direction by looking at the history, current and target revisions, but this feels like fighting the library. Am I missing something or is there a reason why this isn't provided out of the box?
If you want to run to downgrade() of a version, you will need to run alembic downgrade the-version-before-it , which mean it will revert to the version after the version that you want to downgrade. Which is the version before the version that we want to revert.
Delete (or move to another folder) the specific migration file (in migrations/versions folder). The head will automatically revert to the most recent remaining migration. Using stamp will set the db version value to the specified revision; not alter the head revision number.
Alembic is a lightweight database migration tool for SQLAlchemy. It is created by the author of SQLAlchemy and it has become the de-facto standard tool to perform migrations on SQLAlchemy backed databases.
It turns out there's a very simple, pragmatic solution to this:
alembic upgrade <target-revision> || alembic downgrade <target-revision>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With