refactor: undo change in env.py
This commit is contained in:
parent
8815c5ee0d
commit
fdfa2b9bab
1 changed files with 1 additions and 13 deletions
|
|
@ -79,20 +79,8 @@ async def run_async_migrations() -> None:
|
|||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode."""
|
||||
try:
|
||||
# 1. Check if an event loop is already running (e.g., in your application's main thread).
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
# 2. If a loop is running, use it to synchronously run the async task.
|
||||
# This prevents the nested loop error.
|
||||
print("Using existing event loop to run migrations.")
|
||||
loop.run_until_complete(run_async_migrations())
|
||||
|
||||
except RuntimeError:
|
||||
# 3. If no loop is running (e.g., when calling 'alembic upgrade head' directly),
|
||||
# start a new one with asyncio.run().
|
||||
print("Starting new event loop for migrations.")
|
||||
asyncio.run(run_async_migrations())
|
||||
asyncio.run(run_async_migrations())
|
||||
|
||||
|
||||
db_engine = get_relational_engine()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue