diff --git a/alembic.ini b/alembic.ini index f81e7c0..3bb0111 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,8 +35,8 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 -# SQLite URL example -sqlalchemy.url = sqlite:////projects/genericrestapiservice-w6od1p/db.sqlite +# SQLite URL example - Make sure it matches the path in app/database.py +sqlalchemy.url = sqlite:////app/storage/db/db.sqlite [post_write_hooks] # post_write_hooks defines scripts or Python functions that are run diff --git a/alembic/env.py b/alembic/env.py index b134d0c..dde953c 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -4,7 +4,11 @@ import os from pathlib import Path # Add the project root directory to Python's path -sys.path.insert(0, str(Path(__file__).parent.parent)) +project_root = Path(__file__).parent.parent.absolute() +sys.path.insert(0, str(project_root)) + +# Also add the project root to the PYTHONPATH environment variable +os.environ["PYTHONPATH"] = str(project_root) + os.pathsep + os.environ.get("PYTHONPATH", "") from sqlalchemy import engine_from_config from sqlalchemy import pool @@ -23,7 +27,14 @@ fileConfig(config.config_file_name) # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -from app.models import Base +try: + # Try importing directly + from app.models import Base +except ImportError: + # If that fails, try with an explicit import of the app module + import app.models + Base = app.models.Base + target_metadata = Base.metadata # other values from the config, defined by the needs of env.py, diff --git a/app/database.py b/app/database.py index 5f2bb03..06c901c 100644 --- a/app/database.py +++ b/app/database.py @@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker from pathlib import Path # Create the database directory if it doesn't exist -DB_DIR = Path("/projects/genericrestapiservice-w6od1p") +DB_DIR = Path("/app/storage/db") DB_DIR.mkdir(parents=True, exist_ok=True) # Define the SQLite URL