← Files Dispensa: lista de comprasARCHIVED FILE

alembic/env.py

1.39 KB · Nov 19, 2026 · 00:38 UTC

↓ Download file

See the change to this file →

from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

from mcp_despensa_hub.db import VERSION_TABLE, Base, normalize_database_url
from mcp_despensa_hub.settings import Settings

config = context.config

if config.config_file_name is not None:
    fileConfig(config.config_file_name, disable_existing_loggers=False)

target_metadata = Base.metadata


def get_url() -> str:
    return normalize_database_url(Settings().database_url)


def _configure_kwargs() -> dict:
    return {
        "target_metadata": target_metadata,
        "version_table": VERSION_TABLE,
        "include_schemas": True,
    }


def run_migrations_offline() -> None:
    url = get_url()
    context.configure(
        url=url,
        literal_binds=True,
        dialect_opts={"paramstyle": "named"},
        **_configure_kwargs(),
    )

    with context.begin_transaction():
        context.run_migrations()


def run_migrations_online() -> None:
    connectable = engine_from_config(
        {"sqlalchemy.url": get_url()},
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(connection=connection, **_configure_kwargs())

        with context.begin_transaction():
            context.run_migrations()


if context.is_offline_mode():
    run_migrations_offline()
else:
    run_migrations_online()

SHA-256: 3840a49a42c9e6b8e4545a4a2af16b0e8e91135148ccc91c263ab9f8d38a8405