40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from alembic import context
|
|
from sqlalchemy import engine_from_config, pool
|
|
|
|
from euniv.db import database_url
|
|
from euniv.models import Base
|
|
import admin.models # 注册系统配置表
|
|
|
|
config = context.config
|
|
config.set_main_option("sqlalchemy.url", database_url())
|
|
target_metadata = Base.metadata
|
|
|
|
|
|
def run_migrations_offline() -> None:
|
|
context.configure(
|
|
url=database_url(),
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
render_as_batch=True,
|
|
)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online() -> None:
|
|
connectable = engine_from_config(
|
|
config.get_section(config.config_ini_section) or {},
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
with connectable.connect() as connection:
|
|
context.configure(connection=connection, target_metadata=target_metadata, render_as_batch=True)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|