Merge pull request #3395 from tba-code/postgres-url-feature

feat: PostgresProvider - Add POSTGRES_URL_OVERRIDE
This commit is contained in:
boc-the-git 2024-04-04 13:18:45 +11:00 committed by GitHub
commit bae7acbc3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 36 deletions

View File

@ -35,6 +35,7 @@
| POSTGRES_SERVER | postgres | Postgres database server address |
| POSTGRES_PORT | 5432 | Postgres database port |
| POSTGRES_DB | mealie | Postgres database name |
| POSTGRES_URL_OVERRIDE | None | Optional Postgres URL override to use instead of POSTGRES_* variables |
### Email

View File

@ -5,40 +5,39 @@ PostgreSQL might be considered if you need to support many concurrent users. In
**For Environment Variable Configuration, see** [Backend Configuration](./backend-config.md)
```yaml
---
version: "3.7"
services:
mealie:
image: ghcr.io/mealie-recipes/mealie:v1.4.0 # (3)
container_name: mealie
restart: always
ports:
- "9925:9000" # (1)
deploy:
resources:
limits:
memory: 1000M # (2)
depends_on:
- postgres
volumes:
- mealie-data:/app/data/
environment:
# Set Backend ENV Variables Here
- ALLOW_SIGNUP=true
- PUID=1000
- PGID=1000
- TZ=America/Anchorage
- MAX_WORKERS=1
- WEB_CONCURRENCY=1
- BASE_URL=https://mealie.yourdomain.com
# Set Backend ENV Variables Here
ALLOW_SIGNUP: true
PUID: 1000
PGID: 1000
TZ: America/Anchorage
MAX_WORKERS: 1
WEB_CONCURRENCY: 1
BASE_URL: https://mealie.yourdomain.com
# Database Settings
DB_ENGINE: postgres
POSTGRES_USER: mealie
POSTGRES_PASSWORD: mealie
POSTGRES_SERVER: postgres
POSTGRES_PORT: 5432
POSTGRES_DB: mealie
depends_on:
postgres:
condition: service_healthy
# Database Settings
- DB_ENGINE=postgres
- POSTGRES_USER=mealie
- POSTGRES_PASSWORD=mealie
- POSTGRES_SERVER=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=mealie
restart: always
postgres:
container_name: postgres
image: postgres:15
@ -48,12 +47,15 @@ services:
environment:
POSTGRES_PASSWORD: mealie
POSTGRES_USER: mealie
healthcheck:
test: ["CMD", "pg_isready"]
interval: 30s
timeout: 20s
retries: 3
volumes:
mealie-data:
driver: local
mealie-pgdata:
driver: local
```
<!-- Updating This? Be Sure to also update the SQLite Annotations -->

View File

@ -9,12 +9,11 @@ SQLite is a popular, open source, self-contained, zero-configuration database th
**For Environment Variable Configuration, see** [Backend Configuration](./backend-config.md)
```yaml
---
version: "3.7"
services:
mealie:
image: ghcr.io/mealie-recipes/mealie:v1.4.0 # (3)
container_name: mealie
restart: always
ports:
- "9925:9000" # (1)
deploy:
@ -24,19 +23,17 @@ services:
volumes:
- mealie-data:/app/data/
environment:
# Set Backend ENV Variables Here
- ALLOW_SIGNUP=true
- PUID=1000
- PGID=1000
- TZ=America/Anchorage
- MAX_WORKERS=1
- WEB_CONCURRENCY=1
- BASE_URL=https://mealie.yourdomain.com
restart: always
# Set Backend ENV Variables Here
ALLOW_SIGNUP: true
PUID: 1000
PGID: 1000
TZ: America/Anchorage
MAX_WORKERS: 1
WEB_CONCURRENCY: 1
BASE_URL: https://mealie.yourdomain.com
volumes:
mealie-data:
driver: local
```
<!-- Updating This? Be Sure to also update the Postgres Annotations -->

View File

@ -39,18 +39,25 @@ class PostgresProvider(AbstractDBProvider, BaseSettings):
POSTGRES_SERVER: str = "postgres"
POSTGRES_PORT: str = "5432"
POSTGRES_DB: str = "mealie"
POSTGRES_URL_OVERRIDE: str | None = None
model_config = SettingsConfigDict(arbitrary_types_allowed=True, extra="allow")
@property
def db_url(self) -> str:
host = f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}"
if self.POSTGRES_URL_OVERRIDE:
url = PostgresDsn(url=self.POSTGRES_URL_OVERRIDE)
if not url.scheme == ("postgresql"):
raise ValueError("POSTGRES_URL_OVERRIDE scheme must be postgresql")
return str(url)
return str(
PostgresDsn.build(
scheme="postgresql",
username=self.POSTGRES_USER,
password=urlparse.quote_plus(self.POSTGRES_PASSWORD),
host=host,
host=f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}",
path=f"{self.POSTGRES_DB or ''}",
)
)