How to call command.stamp(alembic_cfg, 'head') asynchronously ? #870
Replies: 2 comments 2 replies
-
Alembc's APIs dont have explicit support for async, so when you say you want to run alembic under asyncio, there's ways to do this but they are firstly unnecessary and secondly have some different ways to do it. it depends on what database driver you are using. If you are using a sync database driver, you can just call alembic's commands from an async task, and they will just run and simply block other tasks. if you are using an async database driver then we would assume you are using SQLAlchemy's async api, and if that's the case then youd want to use the run_sync() approach. but...this is all kind of conceptually difficult and IMO unnecessary. migrations are not subject to concurrency unless you are trying to do some kind of thing where you are running migrations against many databases in parallel. I'd use multiprocessing for that. |
Beta Was this translation helpful? Give feedback.
-
oh oh sorry, I also forgot we have an async template as an example, which illustrates how to use run_sync: https://github.com/sqlalchemy/alembic/blob/master/alembic/templates/async/env.py |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to set up by alembic to use async connections , but I'm facing the following error when calling: command.stamp(alembic_cfg, 'head')
I've also tried to await this command, but I still get the same error.
I've updated my env.py based on the details available at the bottom of: https://alembic.sqlalchemy.org/en/latest/cookbook.html
The migration works but the command.stamp doesn't. And I need this call to bootstrap my DB.
Any idea how I can fix this?
I use alembic 1.6.5 with sqlAlchemy 1.4.18
Thanks
Beta Was this translation helpful? Give feedback.
All reactions