env.py 674 Bytes
"""Alembic 环境:全部表定义在 app.models(共用 app.core.db.metadata);引擎由 app.core.db 提供。"""
from alembic import context

from app import models  # noqa: F401  注册全部表
from app.core import db

config = context.config
target_metadata = db.metadata


def run_migrations_online() -> None:
    engine = config.attributes.get("engine") or db.engine()
    with engine.connect() as conn:
        context.configure(connection=conn, target_metadata=target_metadata, compare_type=True,
                          version_table=db.VERSION_TABLE)
        with context.begin_transaction():
            context.run_migrations()


run_migrations_online()