diff --git a/apps/api/src/config/settings.py b/apps/api/src/config/settings.py index d79fbf5..00b8311 100644 --- a/apps/api/src/config/settings.py +++ b/apps/api/src/config/settings.py @@ -117,6 +117,26 @@ class Settings(BaseSettings): rate_limit_enabled: bool = True 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") def _check_production_safety(self) -> "Settings": """Refuse to start with unsafe defaults in non-dev environments."""