Skip to content
Discussion options

You must be logged in to vote

We have an application with schema-based multi-tenancy. Migrations are run by our database tool which internally uses alembic . We need to migrate a lot of databases, so we would like to do in parallel.

But there is an issue with alembic.op (and AFAIU alembic.context). It is not thread-safe. E. g. if one upgrade() starts just after another, Operations.context() overwrites contents of alembic.op with an _install_proxy() call. As a result, both migrations, running in parallel, share the same connection and MigrationContext/Operations instances, which obviously leads to severe consequences.

that's correct, alembic.op is a global variable that is established within the scope of where env.py…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@MrP4p3r
Comment options

@CaselIT
Comment options

@zzzeek
Comment options

@MrP4p3r
Comment options

Answer selected by MrP4p3r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants