From 1461373ec300132bffdf09e9f32d0e49e2c98d2b Mon Sep 17 00:00:00 2001 From: Automated Action Date: Sat, 31 May 2025 13:35:59 +0000 Subject: [PATCH] Fix database path to use relative paths for better compatibility --- alembic.ini | 4 ++-- app/db/session.py | 5 ++++- migrations/env.py | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/alembic.ini b/alembic.ini index b362f89..172a419 100644 --- a/alembic.ini +++ b/alembic.ini @@ -60,8 +60,8 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne # are written from script.py.mako # output_encoding = utf-8 -# SQLite URL using absolute path -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +# SQLite URL - will be dynamically set in env.py +sqlalchemy.url = driver://user:pass@localhost/dbname [post_write_hooks] diff --git a/app/db/session.py b/app/db/session.py index c4a1aea..b8b90cf 100644 --- a/app/db/session.py +++ b/app/db/session.py @@ -3,8 +3,11 @@ from pathlib import Path from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker +# Get the project root directory +PROJECT_ROOT = Path(__file__).parent.parent.parent.absolute() + # Create the directory for the SQLite database if it doesn't exist -DB_DIR = Path("/app") / "storage" / "db" +DB_DIR = PROJECT_ROOT / "app" / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" diff --git a/migrations/env.py b/migrations/env.py index ddcbfbc..5c5c01f 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -3,10 +3,16 @@ from logging.config import fileConfig from alembic import context from sqlalchemy import engine_from_config, pool +# Import db settings +from app.db.session import SQLALCHEMY_DATABASE_URL + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config +# Set the SQLAlchemy URL in the alembic config +config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL) + # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: