44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import sys
|
|
import os
|
|
from logging.config import fileConfig
|
|
from sqlalchemy import engine_from_config, pool
|
|
from alembic import context
|
|
|
|
# Add project root to path
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from app.core.settings import DATABASE_URL
|
|
from app.db.database import Base
|
|
|
|
# Import all models here so Alembic can detect them.
|
|
#
|
|
# `app.db.all_models` is the one that matters. Importing `app.main` reaches
|
|
# most models by accident — routes import what they use — but it missed
|
|
# `user_roles`, `access_groups` and `user_access_groups`, whose every import is
|
|
# function-local. Autogenerate reported all three as removed tables and offered
|
|
# to drop the SBAC schema. See tests/probes/test_model_registry.py.
|
|
import app.db.all_models # noqa: F401
|
|
import app.main
|
|
from app.modules.tenant.models.tenant_contact_model import TenantContact
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
config = context.config
|
|
config.set_main_option("sqlalchemy.url", DATABASE_URL.replace('%', '%%'))
|
|
|
|
if config.config_file_name is not None:
|
|
fileConfig(config.config_file_name)
|
|
|
|
def run_migrations_online():
|
|
connectable = engine_from_config(
|
|
config.get_section(config.config_ini_section),
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
with connectable.connect() as connection:
|
|
context.configure(connection=connection, target_metadata=target_metadata)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
run_migrations_online()
|