INNER CODE UNIT · Python
_run_migrations
KatrielMoses/voidaccess · api/main.py:477
def _run_migrations() -> None:
"""Apply any pending Alembic migrations at startup.
Safe to call on every boot — Alembic is idempotent (already-applied
migrations are skipped). Logs a warning and continues on failure so a
migration error never hard-crashes the API process.
"""
if not os.getenv("DATABASE_URL"):
logger.info("DATABASE_URL not set — skipping migrations")
return
try:
from alembic.config import Config # noqa: PLC0415
from alembic import command # noqa: PLC0415
from alembic.util import CommandError # noqa: PLC0415
import pathlib # noqa: PLC0415
project_root = pathlib.Path(__file__).resolve().parents[1]
ini_path = project_root / "alembic.ini"