
- Add project root to Python path in migrations/env.py - Change database URL configuration to ensure database directory exists - Update alembic.ini to use relative database path - Make database URL configuration more resilient
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from typing import List, Optional
|
|
from pydantic import AnyHttpUrl, EmailStr, validator
|
|
from pydantic_settings import BaseSettings
|
|
from pathlib import Path
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Base
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "SaaS Invoicing Application"
|
|
PROJECT_DESCRIPTION: str = "A SaaS invoicing application API built with FastAPI"
|
|
VERSION: str = "0.1.0"
|
|
|
|
# Server configuration
|
|
SERVER_HOST: str = "http://localhost:8000"
|
|
|
|
# Authentication
|
|
SECRET_KEY: str = "CHANGE_ME_TO_A_SECURE_RANDOM_STRING"
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
|
|
# Database
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
|
|
@property
|
|
def SQLALCHEMY_DATABASE_URL(self) -> str:
|
|
# Ensure the database directory exists
|
|
self.DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
return f"sqlite:///{self.DB_DIR}/db.sqlite"
|
|
|
|
# CORS
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: str | List[str]) -> List[str] | str:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
elif isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
# Emails
|
|
EMAILS_ENABLED: bool = False
|
|
EMAILS_FROM_EMAIL: Optional[EmailStr] = None
|
|
EMAILS_FROM_NAME: Optional[str] = None
|
|
|
|
# First superuser
|
|
FIRST_SUPERUSER_EMAIL: EmailStr = "admin@example.com"
|
|
FIRST_SUPERUSER_PASSWORD: str = "admin"
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings() |