Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple way to tell alembic to migrate to a specific revision?

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?

like image 385
Matt Avatar asked May 04 '16 18:05

Matt


People also ask

How do I downgrade my alembic migration?

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.

How do I change my alembic head?

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.

What is database migration alembic?

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.


1 Answers

It turns out there's a very simple, pragmatic solution to this:

alembic upgrade <target-revision> || alembic downgrade <target-revision> 
like image 138
Matt Avatar answered Sep 22 '22 18:09

Matt