Files
DocsGPT/docsgpt/core/settings/database.py
T
arc53-machine c17b23378e refactor(settings): split Settings into per-domain modules
docsgpt/core/settings.py had grown to 258 fields in one 600-line class,
touched by about two commits a week, with related settings scattered
(GitHub ingest caps inside the embeddings block, API keys in four places,
the OpenAI Responses knobs 100 lines from the other OpenAI fields).

It is now a package: one module per domain (auth, llm, embeddings,
retrieval, vectorstores, database, workers, ingestion, ocr, storage,
connectors, server, events, agents, guardrails, scheduler, sandbox,
speech), each a SettingsGroup owning its fields and validators, composed
by multiple inheritance into the same flat Settings class. Every
attribute name, type, default, alias and constraint is unchanged, so
settings.NAME reads, .env files and test monkeypatches all keep working;
the import path docsgpt.core.settings is the package. Settings.normalize_api_key
is kept as a classmethod for callers that reuse it.

The comment above or beside each field became its Field(description=...),
so the definitions are visible to tooling; the next commit generates the
docs reference from them.

Pitfall recorded for future groups: pydantic collects validators by
method name across the MRO, so two groups naming a validator the same
would silently keep only one. Each group's validator has a unique name.
2026-09-17 11:04:01 +01:00

37 lines
1.3 KiB
Python

"""User-data Postgres and schema management at startup."""
from __future__ import annotations
from typing import Optional
from pydantic import Field, field_validator
from docsgpt.core.db_uri import normalize_postgres_uri
from docsgpt.core.settings._shared import SettingsGroup
class DatabaseSettings(SettingsGroup):
"""The Postgres database holding users, conversations and sources, and what startup may do to it."""
POSTGRES_URI: Optional[str] = Field(default=None, description="User-data Postgres connection URI.")
AUTO_MIGRATE: bool = Field(
default=True,
description="On startup, apply pending Alembic migrations. Disable if you manage schema out-of-band.",
)
AUTO_CREATE_DB: bool = Field(
default=True,
description="On startup, create the target Postgres database if missing (needs CREATEDB privilege).",
)
AUTO_VECTOR_SCHEMA: bool = Field(
default=True,
description=(
"On startup, create the pgvector/graph tables and verify the embedding dimension. No Alembic "
"migration covers the vector DB (it may be a separate cluster); set False to manage it yourself."
),
)
@field_validator("POSTGRES_URI", mode="before")
@classmethod
def _normalize_postgres_uri(cls, v):
return normalize_postgres_uri(v)