refactor: simplify postgresql env vars

This commit is contained in:
Jakub Miazek
2024-03-24 18:19:19 +01:00
parent f7abc9f3b7
commit 7e34800d78
7 changed files with 47 additions and 70 deletions

View File

@@ -21,10 +21,10 @@ class Settings(BaseSettings):
JWT_ALGORITHM: str
JWT_EXPIRE: int
SQL_USER: str
SQL_PASS: str
SQL_HOST: str
SQL_DB: str
POSTGRES_USER: str
POSTGRES_PASSWORD: str
POSTGRES_HOST: str
POSTGRES_DB: str
@computed_field
@property
@@ -57,20 +57,20 @@ class Settings(BaseSettings):
The URL is built using the MultiHostUrl.build method, which takes the following parameters:
- scheme: The scheme of the URL. In this case, it is "postgresql+asyncpg".
- username: The username for the SQL database, retrieved from the SQL_USER environment variable.
- password: The password for the SQL database, retrieved from the SQL_PASS environment variable.
- host: The host of the SQL database, retrieved from the SQL_HOST environment variable.
- path: The path of the SQL database, retrieved from the SQL_DB environment variable.
- username: The username for the Postgres database, retrieved from the POSTGRES_USER environment variable.
- password: The password for the Postgres database, retrieved from the POSTGRES_PASSWORD environment variable.
- host: The host of the Postgres database, retrieved from the POSTGRES_HOST environment variable.
- path: The path of the Postgres database, retrieved from the POSTGRES_DB environment variable.
Returns:
PostgresDsn: The constructed PostgresDsn URL for asyncpg.
"""
return MultiHostUrl.build(
scheme="postgresql+asyncpg",
username=self.SQL_USER,
password=self.SQL_PASS,
host=self.SQL_HOST,
path=self.SQL_DB,
username=self.POSTGRES_USER,
password=self.POSTGRES_PASSWORD,
host=self.POSTGRES_HOST,
path=self.POSTGRES_DB,
)