
- Add pydantic-settings to requirements.txt - Add fallback import for BaseSettings from pydantic if pydantic_settings is not available - Fix ModuleNotFoundError during database migration
34 lines
863 B
Python
34 lines
863 B
Python
from pathlib import Path
|
|
|
|
# Try to import BaseSettings from pydantic_settings (for Pydantic v2+)
|
|
# Fall back to importing from pydantic directly (for Pydantic v1)
|
|
try:
|
|
from pydantic_settings import BaseSettings
|
|
except ImportError:
|
|
from pydantic import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# API configuration
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "RESTAPIService"
|
|
PROJECT_DESCRIPTION: str = "FastAPI REST API Service"
|
|
VERSION: str = "0.1.0"
|
|
|
|
# CORS Origins
|
|
BACKEND_CORS_ORIGINS: list[str] = ["*"]
|
|
|
|
# Database
|
|
DB_DIR = Path("/app") / "storage" / "db"
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# SQLite Database URL
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings()
|