config.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Application settings.
  2. Configuration is read from the environment. For the MVP the two knobs are the
  3. database URL and the ``USE_FAKE_DATA`` flag.
  4. """
  5. from __future__ import annotations
  6. from functools import lru_cache
  7. from pydantic_settings import BaseSettings, SettingsConfigDict
  8. class Settings(BaseSettings):
  9. """Runtime settings, populated from environment variables.
  10. ``DATABASE_URL`` and ``USE_FAKE_DATA`` (case-insensitive) override defaults.
  11. """
  12. model_config = SettingsConfigDict(env_file=".env", extra="ignore")
  13. # Async SQLAlchemy URL. asyncpg driver is required for the async engine.
  14. database_url: str = "postgresql+asyncpg://hsdata:hsdata@localhost:5432/hsdata"
  15. # PostgreSQL schema holding the拼团 funnel tables. Real source is `ads`
  16. # (tables ads.ads_trd_group_funnel_*); set via connection search_path so the
  17. # schema-less ORM table names resolve there. Empty = leave default (public).
  18. db_schema: str = "ads"
  19. # When true, the funnel API serves a realistic in-memory snapshot instead of
  20. # querying Postgres. Default ON so `uvicorn app.main:app` works with zero
  21. # infrastructure. Set USE_FAKE_DATA=false to read the real wide table.
  22. use_fake_data: bool = True
  23. @lru_cache
  24. def get_settings() -> Settings:
  25. """Return a cached Settings instance."""
  26. return Settings()