updated db_seetup

Add_History
ahmed.mujtaba 2026-08-20 17:59:48 +05:00
parent f1758ac9bd
commit a9da4c2b81
1 changed files with 4 additions and 3 deletions

View File

@ -76,7 +76,7 @@ class Settings(BaseSettings):
return value
def url(self, *, async_driver: bool = True) -> URL:
"""DSN with the driver forced; `sslmode` is translated to asyncpg's `ssl`."""
"""DSN with the driver forced; `sslmode` is mapped to asyncpg's `ssl` mode name."""
url = (
make_url(self.database_url)
if self.database_url
@ -92,8 +92,9 @@ class Settings(BaseSettings):
query = dict(url.query)
if self.db_sslmode:
query.setdefault("sslmode", self.db_sslmode)
if async_driver and query.pop("sslmode", None) not in (None, "disable", "allow", "prefer"):
query["ssl"] = "true"
# asyncpg accepts ssl as an SSLMode name (require, verify-full, …), not "true".
if async_driver and (mode := query.pop("sslmode", None)) is not None:
query["ssl"] = mode
driver = "asyncpg" if async_driver else "psycopg2"
return url.set(drivername=f"postgresql+{driver}", query=query)