From 0b8a59edcb659db0d09a91ccd9a2d9a9a5339dbd Mon Sep 17 00:00:00 2001 From: Prashant Shendre Date: Tue, 13 Oct 2026 16:49:37 +0530 Subject: [PATCH] Ensured alembic path has proper root --- backend/alembic.ini | 2 +- backend/alembic/env.py | 12 +++++++++++- backend/app/models/user.py | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/alembic.ini b/backend/alembic.ini index 7f71dd3..e04f5f8 100644 --- a/backend/alembic.ini +++ b/backend/alembic.ini @@ -1,6 +1,6 @@ [alembic] script_location = alembic -prepend_sys_path = . +prepend_sys_path = . .. [loggers] keys = root,sqlalchemy,alembic diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 290f9e8..0a32c66 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -1,8 +1,18 @@ import os +import sys +from pathlib import Path from logging.config import fileConfig from sqlalchemy import engine_from_config, pool from alembic import context +# Ensure project_code root is in sys.path so 'backend.app' can be imported anywhere +backend_dir = Path(__file__).resolve().parents[1] +code_root = backend_dir.parent +if str(code_root) not in sys.path: + sys.path.insert(0, str(code_root)) +if str(backend_dir) not in sys.path: + sys.path.insert(0, str(backend_dir)) + # Alembic Config object config = context.config @@ -12,7 +22,7 @@ if config.config_file_name is not None: # Import models target metadata from backend.app.models.user import Base -target_metadata = Base.metadata +target_metadata = Base.metadata if Base is not None else None def get_url(): return os.getenv( diff --git a/backend/app/models/user.py b/backend/app/models/user.py index 68b6728..80a73fb 100644 --- a/backend/app/models/user.py +++ b/backend/app/models/user.py @@ -28,6 +28,7 @@ try: except ImportError: # Lightweight fallback model when SQLAlchemy is not loaded in current environment + Base = None class User: def __init__(self, subject: str, email: str, full_name: Optional[str] = None, is_active: bool = True, id: Optional[str] = None):