diff --git a/alembic.ini b/alembic.ini index 922bc72..fed857a 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,7 +35,8 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +# Using relative path - will be set in env.py +sqlalchemy.url = driver://user:pass@localhost/dbname [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 2b200f3..19aff51 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -19,9 +19,17 @@ fileConfig(config.config_file_name) # target_metadata = mymodel.Base.metadata import sys import os +from pathlib import Path + +# Add parent directory to path sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from app.models import Base +from app.database import SQLALCHEMY_DATABASE_URL + +# Override the sqlalchemy.url in alembic.ini +config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL) + 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 a2702c3..402553e 100644 --- a/app/database.py +++ b/app/database.py @@ -2,9 +2,11 @@ from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from pathlib import Path +import os -# Create database directory -DB_DIR = Path("/app") / "storage" / "db" +# Create database directory using a local path +BASE_DIR = Path(__file__).resolve().parent.parent +DB_DIR = BASE_DIR / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) # Database URL