From 61c5a0945a3f7455d450de358169690913231984 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 15 May 2025 19:51:12 +0000 Subject: [PATCH] Update database path configuration to use absolute path - Updated alembic.ini to use absolute SQLite path - Ensured DB_DIR creation in config settings - Removed duplicate directory creation code generated with BackendIM... (backend.im) --- alembic.ini | 1 + alembic/env.py | 8 ++++++++ app/core/config.py | 9 ++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/alembic.ini b/alembic.ini index 8477707..cb5aa80 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,6 +35,7 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 +# sqlalchemy.url is now set dynamically in env.py sqlalchemy.url = sqlite:////app/storage/db/db.sqlite # Logging configuration diff --git a/alembic/env.py b/alembic/env.py index 1d4aa74..859e439 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,9 @@ from logging.config import fileConfig +import sys +import os + +# Add the parent directory to sys.path +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from sqlalchemy import engine_from_config from sqlalchemy import pool @@ -12,6 +17,9 @@ from app.db.base import Base # access to the values within the .ini file in use. config = context.config +# Override sqlalchemy.url with the value from settings +config.set_main_option("sqlalchemy.url", settings.SQLALCHEMY_DATABASE_URL) + # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: diff --git a/app/core/config.py b/app/core/config.py index b7bfc3d..f6f79d0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -20,7 +20,9 @@ class Settings(BaseSettings): # Database settings DB_DIR: Path = Path("/app") / "storage" / "db" - SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" + DB_DIR.mkdir(parents=True, exist_ok=True) + DB_PATH: Path = DB_DIR / "db.sqlite" + SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_PATH}" # Password reset settings PASSWORD_RESET_TOKEN_EXPIRE_HOURS: int = 24 @@ -39,7 +41,4 @@ class Settings(BaseSettings): case_sensitive = True # Create the settings object -settings = Settings() - -# Ensure the database directory exists -settings.DB_DIR.mkdir(parents=True, exist_ok=True) \ No newline at end of file +settings = Settings() \ No newline at end of file