diff --git a/migrations/env.py b/migrations/env.py index 9b22d44..a151ee9 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,12 +1,39 @@ +import os +import sys from logging.config import fileConfig - -from sqlalchemy import engine_from_config -from sqlalchemy import pool +from pathlib import Path from alembic import context +from sqlalchemy import engine_from_config, pool -from app.models import Base -from app.core.config import settings +# Add the project root directory to the Python path +# This ensures that the 'app' module can be imported correctly +project_root = str(Path(__file__).parents[1].absolute()) +if project_root not in sys.path: + sys.path.insert(0, project_root) + +# For containerized environments where the app might be in a different location +container_paths = [ + "/app/repo", # Common container path + "/app", # Another common container path +] + +for container_path in container_paths: + if os.path.exists(container_path) and container_path not in sys.path: + sys.path.insert(0, container_path) + +# Now we can import our application modules +try: + from app.core.config import settings # noqa: F401 - Used in later operations + from app.models import Base +except ImportError as e: + print(f"Error importing app modules: {e}") + print(f"Current sys.path: {sys.path}") + print("Looking for app module in these directories:") + for path in sys.path: + if os.path.isdir(path): + print(f" - {path}: {os.listdir(path)}") + raise # this is the Alembic Config object, which provides # access to the values within the .ini file in use.