Add support for setting POSTGRES_PORT (#333)

Co-authored-by: Martin Conraux <rhodes@protonmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Martin
2024-03-12 14:39:53 +01:00
committed by GitHub
parent c3f77eb713
commit 5ad33845c9
5 changed files with 7 additions and 1 deletions

1
.env
View File

@@ -26,6 +26,7 @@ SMTP_PORT=587
# Postgres # Postgres
POSTGRES_SERVER=localhost POSTGRES_SERVER=localhost
POSTGRES_PORT=5432
POSTGRES_DB=app POSTGRES_DB=app
POSTGRES_USER=postgres POSTGRES_USER=postgres
POSTGRES_PASSWORD=changethis POSTGRES_PASSWORD=changethis

View File

@@ -32,8 +32,9 @@ def get_url():
user = os.getenv("POSTGRES_USER", "postgres") user = os.getenv("POSTGRES_USER", "postgres")
password = os.getenv("POSTGRES_PASSWORD", "") password = os.getenv("POSTGRES_PASSWORD", "")
server = os.getenv("POSTGRES_SERVER", "db") server = os.getenv("POSTGRES_SERVER", "db")
port = os.getenv("POSTGRES_PORT", "5432")
db = os.getenv("POSTGRES_DB", "app") db = os.getenv("POSTGRES_DB", "app")
return f"postgresql+psycopg://{user}:{password}@{server}/{db}" return f"postgresql+psycopg://{user}:{password}@{server}:{port}/{db}"
def run_migrations_offline(): def run_migrations_offline():

View File

@@ -48,6 +48,7 @@ class Settings(BaseSettings):
PROJECT_NAME: str PROJECT_NAME: str
SENTRY_DSN: HttpUrl | None = None SENTRY_DSN: HttpUrl | None = None
POSTGRES_SERVER: str POSTGRES_SERVER: str
POSTGRES_PORT: int = 5432
POSTGRES_USER: str POSTGRES_USER: str
POSTGRES_PASSWORD: str POSTGRES_PASSWORD: str
POSTGRES_DB: str = "" POSTGRES_DB: str = ""
@@ -60,6 +61,7 @@ class Settings(BaseSettings):
username=self.POSTGRES_USER, username=self.POSTGRES_USER,
password=self.POSTGRES_PASSWORD, password=self.POSTGRES_PASSWORD,
host=self.POSTGRES_SERVER, host=self.POSTGRES_SERVER,
port=self.POSTGRES_PORT,
path=self.POSTGRES_DB, path=self.POSTGRES_DB,
) )

View File

@@ -137,6 +137,7 @@ You can set several variables, like:
* `SMTP_PASSWORD`: The SMTP server password to send emails. * `SMTP_PASSWORD`: The SMTP server password to send emails.
* `EMAILS_FROM_EMAIL`: The email account to send emails from. * `EMAILS_FROM_EMAIL`: The email account to send emails from.
* `POSTGRES_SERVER`: The hostname of the PostgreSQL server. You can leave the default of `db`, provided by the same Docker Compose. You normally wouldn't need to change this unless you are using a third-party provider. * `POSTGRES_SERVER`: The hostname of the PostgreSQL server. You can leave the default of `db`, provided by the same Docker Compose. You normally wouldn't need to change this unless you are using a third-party provider.
* `POSTGRES_PORT`: The port of the PostgreSQL server. You can leave the default. You normally wouldn't need to change this unless you are using a third-party provider.
* `POSTGRES_PASSWORD`: The Postgres password. * `POSTGRES_PASSWORD`: The Postgres password.
* `POSTGRES_USER`: The Postgres user, you can leave the default. * `POSTGRES_USER`: The Postgres user, you can leave the default.
* `POSTGRES_DB`: The database name to use for this application. You can leave the default of `app`. * `POSTGRES_DB`: The database name to use for this application. You can leave the default of `app`.

View File

@@ -100,6 +100,7 @@ services:
- SMTP_PASSWORD=${SMTP_PASSWORD} - SMTP_PASSWORD=${SMTP_PASSWORD}
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL} - EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
- POSTGRES_SERVER=db - POSTGRES_SERVER=db
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB} - POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER?Variable not set} - POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}