Skip to content

Commit 0d7476b

Browse files
uepochMartin Conrauxtiangolo
authored
✨ Add support for setting POSTGRES_PORT (fastapi#333)
Co-authored-by: Martin Conraux <[email protected]> Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 28ffdd0 commit 0d7476b

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

backend/app/alembic/env.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def get_url():
3232
user = os.getenv("POSTGRES_USER", "postgres")
3333
password = os.getenv("POSTGRES_PASSWORD", "")
3434
server = os.getenv("POSTGRES_SERVER", "db")
35+
port = os.getenv("POSTGRES_PORT", "5432")
3536
db = os.getenv("POSTGRES_DB", "app")
36-
return f"postgresql+psycopg://{user}:{password}@{server}/{db}"
37+
return f"postgresql+psycopg://{user}:{password}@{server}:{port}/{db}"
3738

3839

3940
def run_migrations_offline():

backend/app/core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def server_host(self) -> str:
4848
PROJECT_NAME: str
4949
SENTRY_DSN: HttpUrl | None = None
5050
POSTGRES_SERVER: str
51+
POSTGRES_PORT: int = 5432
5152
POSTGRES_USER: str
5253
POSTGRES_PASSWORD: str
5354
POSTGRES_DB: str = ""
@@ -60,6 +61,7 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
6061
username=self.POSTGRES_USER,
6162
password=self.POSTGRES_PASSWORD,
6263
host=self.POSTGRES_SERVER,
64+
port=self.POSTGRES_PORT,
6365
path=self.POSTGRES_DB,
6466
)
6567

deployment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ You can set several variables, like:
137137
* `SMTP_PASSWORD`: The SMTP server password to send emails.
138138
* `EMAILS_FROM_EMAIL`: The email account to send emails from.
139139
* `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.
140+
* `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.
140141
* `POSTGRES_PASSWORD`: The Postgres password.
141142
* `POSTGRES_USER`: The Postgres user, you can leave the default.
142143
* `POSTGRES_DB`: The database name to use for this application. You can leave the default of `app`.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ services:
100100
- SMTP_PASSWORD=${SMTP_PASSWORD}
101101
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
102102
- POSTGRES_SERVER=db
103+
- POSTGRES_PORT=${POSTGRES_PORT}
103104
- POSTGRES_DB=${POSTGRES_DB}
104105
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
105106
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}

0 commit comments

Comments
 (0)