From c7bb49776cd120dcfbb222cfefca687e8b762fd6 Mon Sep 17 00:00:00 2001 From: v6ole Date: Tue, 28 Jul 2026 17:38:17 +0800 Subject: [PATCH] fix(migrations): support virtualenv Alembic execution --- backend/alembic/env.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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