Commit 45cd648
fix(rest-postgres): idempotent DB init so a partial init can't silently drop databases (#2623)
## Problem
`rest-api/deploy/kustomize/base/postgres/init-configmap.yaml` runs once
via `docker-entrypoint-initdb.d` under `psql -v ON_ERROR_STOP=1`. If any
statement errors, psql aborts and the remaining `CREATE
DATABASE`/`CREATE USER` statements are skipped, leaving a **partial**
state — e.g. `nico`+`keycloak` created but
`temporal`/`temporal_visibility` missing.
Because PostgreSQL only runs init scripts on an **empty** data dir, the
script **never re-runs**, so the missing databases are silent and
permanent. The Temporal install then fails its pre-install hook:
```
Error: failed pre-install: timed out waiting for the condition
FATAL: password authentication failed for user "temporal"
DETAIL: Role "temporal" does not exist.
```
Reproduced during a clean v0.10.3 bring-up.
## Fix
Make every database/role creation **idempotent**:
- `SELECT … WHERE NOT EXISTS (…)\gexec` guard for `CREATE DATABASE`
- `DO $$ … IF NOT EXISTS … $$` for roles
The script is now safe to re-run, and a single benign "already exists"
error no longer aborts it and skips later databases.
## Test
Re-applied against a partially-initialized postgres (had only
nico+keycloak): all four DBs (`nico`, `keycloak`, `temporal`,
`temporal_visibility`) present; Temporal install proceeds.
Signed-off-by: ekirson <ekirson@nvidia.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Hasan Khan <hasank@nvidia.com>1 parent d406520 commit 45cd648
1 file changed
Lines changed: 17 additions & 18 deletions
Lines changed: 17 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | | - | |
27 | 24 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
35 | | - | |
36 | 33 | | |
37 | | - | |
38 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
45 | | - | |
46 | 44 | | |
47 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
0 commit comments