Files
fast-next-template/backend/app/core/config.py
Felipe Cardoso 481b6d618e Refactor and reorganize Alembic and database configuration.
Moved Alembic files into the `app/alembic` directory and updated related paths. Consolidated database configuration in `config.py`, leveraging environment variables and ensuring centralized management. Updated Docker Compose to include `.env` files, providing a more consistent environment setup.
2025-02-28 09:26:25 +01:00

48 lines
1.4 KiB
Python

from pydantic_settings import BaseSettings
from typing import Optional, List
class Settings(BaseSettings):
PROJECT_NAME: str = "App"
VERSION: str = "1.0.0"
API_V1_STR: str = "/api/v1"
# Database configuration
POSTGRES_USER: str = "postgres"
POSTGRES_PASSWORD: str = "postgres"
POSTGRES_HOST: str = "localhost"
POSTGRES_PORT: str = "5432"
POSTGRES_DB: str = "app"
DATABASE_URL: Optional[str] = None
@property
def database_url(self) -> str:
"""
Get the SQLAlchemy database URL.
If DATABASE_URL is explicitly set, use that.
Otherwise, construct from components.
"""
if self.DATABASE_URL:
return self.DATABASE_URL
self.DATABASE_URL = f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
return self.DATABASE_URL
# JWT configuration
SECRET_KEY: str = "your_secret_key_here"
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# CORS configuration
BACKEND_CORS_ORIGINS: List[str] = ["http://localhost:3000"]
# Admin user
FIRST_SUPERUSER_EMAIL: Optional[str] = None
FIRST_SUPERUSER_PASSWORD: Optional[str] = None
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = True
settings = Settings()