Fix Pydantic model error in config.py and update DB configuration

This commit is contained in:
Automated Action 2025-05-24 15:42:36 +00:00
parent eb8caf0254
commit d145e0d3f6
3 changed files with 16 additions and 12 deletions

View File

@ -2,6 +2,9 @@ from typing import List
from pydantic_settings import BaseSettings
from pathlib import Path
# Create DB directory outside the model
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
@ -9,13 +12,12 @@ class Settings(BaseSettings):
ALLOWED_ORIGINS: List[str] = ["*"]
# Database settings
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
class Config:
env_file = ".env"
case_sensitive = True
model_config = {
"env_file": ".env",
"case_sensitive": True
}
settings = Settings()

View File

@ -1,13 +1,9 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pathlib import Path
from app.core.config import settings
# Create db directory if it doesn't exist
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Use the SQLALCHEMY_DATABASE_URL from settings
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
engine = create_engine(
SQLALCHEMY_DATABASE_URL,

6
test_config.py Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
from app.core.config import settings
print("Settings loaded successfully")
print(f"API_V1_STR: {settings.API_V1_STR}")
print(f"DATABASE_URL: {settings.DATABASE_URL}")