Skip to content

Commit 34fdba7

Browse files
committed
fix(integrations): self-heal missing intelligence_app DB in _intelligence overlay
The activation overlay's docker-compose.yml relied on a bind-mounted docker/init-db script to create the intelligence_app database, but the CLI copies only docker-compose.yml into scaffolded projects. The mount source never exists there, Docker creates it as an empty directory, postgres initializes without intelligence_app, and the composite's migrations fail: 'database "intelligence_app" does not exist' → 'dependency failed to start: container ...intelligence-1 is unhealthy'. Make the compose file self-contained: - Set POSTGRES_DB: intelligence_app (drop the init-db bind mount and the now-unused init script; the shadow DB it also created is only used by repo-local dev tooling, never by the composite). - Add an idempotent provision-db one-shot that creates the database when missing. POSTGRES_DB only applies on first init of an empty volume, and the volume is shared across all scaffolds via the fixed compose project name — so machines that already hit the bug have a data volume without the database. The one-shot heals those on the next 'docker compose up' with no manual 'down -v'. - Gate the composite on provision-db completion instead of postgres health, and align the postgres healthcheck dbname.
1 parent 0419941 commit 34fdba7

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

examples/integrations/_intelligence/docker-compose.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ services:
2424
environment:
2525
POSTGRES_USER: intelligence
2626
POSTGRES_PASSWORD: intelligence
27-
POSTGRES_DB: postgres
27+
# Created on first init of an empty data volume. Volumes initialized
28+
# before this default existed are healed by the provision-db one-shot
29+
# below, so do not rely on this alone.
30+
POSTGRES_DB: intelligence_app
2831
volumes:
2932
- postgres-data:/var/lib/postgresql/data
30-
- ./docker/init-db:/docker-entrypoint-initdb.d:ro
3133
healthcheck:
32-
test: ["CMD-SHELL", "pg_isready -U intelligence -d postgres"]
34+
test: ["CMD-SHELL", "pg_isready -U intelligence -d intelligence_app"]
3335
interval: 5s
3436
timeout: 3s
3537
retries: 5
@@ -52,6 +54,33 @@ services:
5254
networks:
5355
- intelligence
5456

57+
# ---------------------------------------------------------------------------
58+
# Database provisioning (one-shot)
59+
# ---------------------------------------------------------------------------
60+
# Ensures the intelligence_app database exists before the composite runs its
61+
# migrations. POSTGRES_DB only takes effect on first init of an EMPTY data
62+
# volume, and the postgres-data volume is shared across every project that
63+
# uses this compose file (fixed project name above) — so a volume created by
64+
# an earlier compose revision may not have the database. CREATE DATABASE has
65+
# no IF NOT EXISTS, hence the pg_database existence check. Idempotent.
66+
provision-db:
67+
image: postgres:16-alpine
68+
depends_on:
69+
postgres:
70+
condition: service_healthy
71+
environment:
72+
PGPASSWORD: intelligence
73+
entrypoint: ["sh", "-c"]
74+
command:
75+
- |
76+
psql -h postgres -U intelligence -d postgres -v ON_ERROR_STOP=1 -tAc \
77+
"SELECT 1 FROM pg_database WHERE datname = 'intelligence_app'" | grep -q 1 \
78+
|| psql -h postgres -U intelligence -d postgres -v ON_ERROR_STOP=1 \
79+
-c "CREATE DATABASE intelligence_app"
80+
restart: "no"
81+
networks:
82+
- intelligence
83+
5584
# ---------------------------------------------------------------------------
5685
# Intelligence composite (app-api + realtime-gateway + thread-culler +
5786
# db-migrations, all in one container under s6-overlay)
@@ -77,8 +106,8 @@ services:
77106
THREAD_STALE_HOURS: "${THREAD_STALE_HOURS:-3}"
78107
THREAD_CULL_BATCH_SIZE: "${THREAD_CULL_BATCH_SIZE:-1000}"
79108
depends_on:
80-
postgres:
81-
condition: service_healthy
109+
provision-db:
110+
condition: service_completed_successfully
82111
redis:
83112
condition: service_healthy
84113
restart: unless-stopped

examples/integrations/_intelligence/docker/init-db/01-create-databases.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)