fix: auto-convert postgres:// and postgresql:// to postgresql+asyncpg:// in settings
Some checks failed
CI / API Lint (push) Has been cancelled
CI / Detect changes (push) Has been cancelled
CI / API Tests (push) Has been cancelled
CI / Scanner Lint (push) Has been cancelled
CI / Scanner Tests (push) Has been cancelled
CI / Banner Lint & Typecheck (push) Has been cancelled
CI / Banner Tests (push) Has been cancelled
CI / Banner Build (push) Has been cancelled
CI / Admin UI Typecheck (push) Has been cancelled
CI / Admin UI Tests (push) Has been cancelled
CI / Admin UI Build (push) Has been cancelled
Some checks failed
CI / API Lint (push) Has been cancelled
CI / Detect changes (push) Has been cancelled
CI / API Tests (push) Has been cancelled
CI / Scanner Lint (push) Has been cancelled
CI / Scanner Tests (push) Has been cancelled
CI / Banner Lint & Typecheck (push) Has been cancelled
CI / Banner Tests (push) Has been cancelled
CI / Banner Build (push) Has been cancelled
CI / Admin UI Typecheck (push) Has been cancelled
CI / Admin UI Tests (push) Has been cancelled
CI / Admin UI Build (push) Has been cancelled
This commit is contained in:
@@ -117,6 +117,26 @@ class Settings(BaseSettings):
|
|||||||
rate_limit_enabled: bool = True
|
rate_limit_enabled: bool = True
|
||||||
rate_limit_per_minute: int = 120
|
rate_limit_per_minute: int = 120
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
def _normalize_database_url(self) -> "Settings":
|
||||||
|
"""Auto-fix common database URL schemes for asyncpg compatibility.
|
||||||
|
|
||||||
|
Platforms like Easypanel emit DATABASE_URL as ``postgres://...``
|
||||||
|
(shortcut or legacy scheme). SQLAlchemy expects the dialect name
|
||||||
|
``postgresql://`` and we need the ``+asyncpg`` driver suffix for
|
||||||
|
the async engine. Normalise both cases here so the rest of the
|
||||||
|
codebase can always assume ``postgresql+asyncpg://``.
|
||||||
|
"""
|
||||||
|
if self.database_url.startswith("postgres://"):
|
||||||
|
self.database_url = self.database_url.replace(
|
||||||
|
"postgres://", "postgresql+asyncpg://", 1,
|
||||||
|
)
|
||||||
|
elif self.database_url.startswith("postgresql://"):
|
||||||
|
self.database_url = self.database_url.replace(
|
||||||
|
"postgresql://", "postgresql+asyncpg://", 1,
|
||||||
|
)
|
||||||
|
return self
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def _check_production_safety(self) -> "Settings":
|
def _check_production_safety(self) -> "Settings":
|
||||||
"""Refuse to start with unsafe defaults in non-dev environments."""
|
"""Refuse to start with unsafe defaults in non-dev environments."""
|
||||||
|
|||||||
Reference in New Issue
Block a user