2025-06-09 13:37:02 +00:00

28 lines
793 B
Python

from pathlib import Path
from pydantic import field_validator
from pydantic_settings import BaseSettings
# Build paths
BASE_DIR = Path(__file__).resolve().parent.parent.parent
class Settings(BaseSettings):
PROJECT_NAME: str = "Barebones Todo API"
API_V1_STR: str = "/api/v1"
# SQLite Database settings
DB_DIR: Path = BASE_DIR / "storage" / "db"
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
@field_validator("SQLALCHEMY_DATABASE_URL")
def validate_db_url(cls, v, values):
# Ensure directory exists
db_dir = values.data.get("DB_DIR")
if db_dir:
db_dir.mkdir(parents=True, exist_ok=True)
return v
class Config:
env_file = ".env"
case_sensitive = True
settings = Settings()