23 lines
821 B
Python
23 lines
821 B
Python
"""Alembic-Umgebung; die URL kommt aus der Konfiguration (aiw migrate) oder AIW_DATABASE_URL."""
|
|
|
|
from alembic import context
|
|
from sqlalchemy import engine_from_config, pool
|
|
|
|
from app.core.config import get_settings
|
|
from app.models import Base
|
|
|
|
config = context.config
|
|
if not config.get_main_option("sqlalchemy.url"):
|
|
config.set_main_option("sqlalchemy.url", get_settings().database_url.replace("%", "%%"))
|
|
|
|
|
|
def run() -> None:
|
|
engine = engine_from_config(config.get_section(config.config_ini_section, {}), prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool)
|
|
with engine.connect() as connection:
|
|
context.configure(connection=connection, target_metadata=Base.metadata, compare_type=True)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
run()
|