From 06dafd5b0c07c59d997ab6a6b154dc08a38f8998 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Fri, 16 May 2025 15:01:25 +0000 Subject: [PATCH] Fix Alembic migration import error and database path issues --- alembic.ini | 2 +- app/core/config.py | 4 +++- migrations/env.py | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/alembic.ini b/alembic.ini index 634a012..29b9bdf 100644 --- a/alembic.ini +++ b/alembic.ini @@ -36,7 +36,7 @@ script_location = migrations # output_encoding = utf-8 # SQLite URL example -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +sqlalchemy.url = sqlite:///%(here)s/storage/db/db.sqlite [post_write_hooks] # post_write_hooks defines scripts or Python functions that are run diff --git a/app/core/config.py b/app/core/config.py index 9735f8f..1e7bbf0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -21,7 +21,9 @@ class Settings(BaseSettings): raise ValueError(v) # Database - DB_DIR: Path = Path("/app") / "storage" / "db" + # Get the project root directory dynamically + BASE_DIR: Path = Path(__file__).parent.parent.parent.absolute() + DB_DIR: Path = BASE_DIR / "storage" / "db" class Config: case_sensitive = True diff --git a/migrations/env.py b/migrations/env.py index 55d5b5a..525e602 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,4 +1,9 @@ from logging.config import fileConfig +import sys +from pathlib import Path + +# Add the project root directory to the Python path +sys.path.insert(0, str(Path(__file__).parent.parent.absolute())) from sqlalchemy import engine_from_config from sqlalchemy import pool