From fd962ad54c396e3231002f315e7a2e1896d38d38 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Mon, 12 May 2025 13:40:28 +0000 Subject: [PATCH] Fix alembic migration issues by adding project to Python path and fixing pydantic config generated with BackendIM... (backend.im) --- alembic/env.py | 7 ++++++- app/core/config.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/alembic/env.py b/alembic/env.py index 11d36ba..8c0ee15 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,9 @@ from logging.config import fileConfig +import sys +from pathlib import Path + +# Add the project root directory to Python's path +sys.path.insert(0, str(Path(__file__).parent.parent)) from sqlalchemy import engine_from_config from sqlalchemy import pool @@ -6,7 +11,7 @@ from sqlalchemy import pool from alembic import context from app.core.config import settings -from app.models import Base +from app.core.database import Base # this is the Alembic Config object, which provides # access to the values within the .ini file in use. diff --git a/app/core/config.py b/app/core/config.py index e0ee183..34dfb07 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,16 +1,19 @@ import os from pathlib import Path -from typing import Optional +from typing import Optional, ClassVar from pydantic_settings import BaseSettings +# Create DB directory path +DB_PATH = Path("/projects/weatherdataapi-2z0ghm") / "app" / "storage" / "db" +DB_PATH.mkdir(parents=True, exist_ok=True) + class Settings(BaseSettings): API_V1_STR: str = "/api/v1" PROJECT_NAME: str = "Weather Data API" - + # Database configuration - DB_DIR = Path("/app") / "storage" / "db" - DB_DIR.mkdir(parents=True, exist_ok=True) - SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" + DB_DIR: ClassVar[Path] = DB_PATH + SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_PATH}/db.sqlite" # OpenWeatherMap API configuration OPENWEATHERMAP_API_KEY: Optional[str] = os.getenv("OPENWEATHERMAP_API_KEY")