37

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?

Matt
  • 2,153
  • 1
  • 18
  • 29

1 Answers1

52

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

alembic upgrade <target-revision> || alembic downgrade <target-revision>
Matt
  • 2,153
  • 1
  • 18
  • 29
  • This is fine but there might be times you don't want migrations to run past a certain point, like if you're trying to resolve conflicts or fix something in a migration that's being developed. – trpt4him Apr 29 '22 at 15:14