diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 100dd2d..486aa98 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -1,10 +1,18 @@ import asyncio +import sys from logging.config import fileConfig +from pathlib import Path from sqlalchemy import pool from sqlalchemy.engine import Connection from sqlalchemy.ext.asyncio import async_engine_from_config from alembic import context +# Ensure Alembic works both in the container and when invoked from a virtualenv +# on a server where the console-script directory would otherwise be sys.path[0]. +BACKEND_ROOT = Path(__file__).resolve().parents[1] +if str(BACKEND_ROOT) not in sys.path: + sys.path.insert(0, str(BACKEND_ROOT)) + from app.database import Base from app.models import * # noqa: import all models from app.config import settings