2efd3ce1a6
- 删除 gx_gp_monitor/ 旧项目目录(Flask CLI 架构) - 删除 app.py(旧 WSGI 入口) - 更新 alembic/env.py 为异步引擎(create_async_engine + run_sync)
34 lines
1009 B
Python
34 lines
1009 B
Python
import asyncio
|
|
from alembic import context
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from app.models.announcement import Base
|
|
from app.config import settings
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
|
|
def run_migrations_offline():
|
|
context.configure(url=settings.database_url, target_metadata=target_metadata,
|
|
literal_binds=True, dialect_opts={"paramstyle": "named"})
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def do_run_migrations(connection):
|
|
context.configure(connection=connection, target_metadata=target_metadata)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
async def run_migrations_online():
|
|
connectable = create_async_engine(settings.database_url, echo=True)
|
|
async with connectable.connect() as connection:
|
|
await connection.run_sync(do_run_migrations)
|
|
await connectable.dispose()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
asyncio.run(run_migrations_online())
|