Async migration with asyncpg #1208
-
Hello. I use sqlmodel with asyncpg. Is it possible to run an async migration?
|
Beta Was this translation helpful? Give feedback.
Answered by
CaselIT
Mar 21, 2023
Replies: 2 comments 4 replies
-
what we have for asyncio is the async template , you can find docs here: https://alembic.sqlalchemy.org/en/latest/cookbook.html#using-asyncio-with-alembic |
Beta Was this translation helpful? Give feedback.
3 replies
-
You seem to be trying to use an async upgrade. That does not work. 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. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
redmonkez12
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
this will work even if the dialect is async and it will not block the loop.