Skip to content

Async migration with asyncpg #1208

Closed Answered by CaselIT
redmonkez12 asked this question in Usage Questions
Mar 21, 2023 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

You seem to be trying to use an async upgrade. That does not work.
You can do that, but you just need to use the plain session:

def upgrade() -> None:
    # note the use of get_bind() here to use the same transaction used by alembic
    with Session(op.get_bind()) as session: 
            markets = [
                Market(name="forex"),
                Market(name="crypto"),
                Market(name="commodities"),
                Market(name="stocks"),
            ]

            session.add_all(markets)
            session.commit()

this will work even if the dialect is async and it will not block the loop.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@redmonkez12
Comment options

@zzzeek
Comment options

@redmonkez12
Comment options

Comment options

You must be logged in to vote
1 reply
@redmonkez12
Comment options

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