Fix Alembic migration error by adding project root to Python path and updating Pydantic config

- Added project root directory to Python path in alembic/env.py
- Updated Pydantic Settings class to use ClassVar typing for DB_DIR
- Updated Config class to new Pydantic v2 model_config format

generated with BackendIM... (backend.im)
This commit is contained in:
Automated Action 2025-05-12 12:36:07 +00:00
parent abc7a8572f
commit c2506a9e3f
2 changed files with 12 additions and 6 deletions

View File

@ -1,4 +1,9 @@
from logging.config import fileConfig from logging.config import fileConfig
import os
import sys
# Add the project root directory to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from sqlalchemy import engine_from_config from sqlalchemy import engine_from_config
from sqlalchemy import pool from sqlalchemy import pool

View File

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import List from typing import List, ClassVar
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings
@ -18,7 +18,7 @@ class Settings(BaseSettings):
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# Database # Database
DB_DIR = Path("/app") / "storage" / "db" DB_DIR: ClassVar[Path] = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True) DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
@ -26,10 +26,11 @@ class Settings(BaseSettings):
STRIPE_API_KEY: str = "your-stripe-api-key" STRIPE_API_KEY: str = "your-stripe-api-key"
STRIPE_WEBHOOK_SECRET: str = "your-stripe-webhook-secret" STRIPE_WEBHOOK_SECRET: str = "your-stripe-webhook-secret"
class Config: model_config = {
env_file = ".env" "env_file": ".env",
env_file_encoding = "utf-8" "env_file_encoding": "utf-8",
case_sensitive = True "case_sensitive": True
}
settings = Settings() settings = Settings()