From 8b84bba165a6662d9af7fba8fed41f6f8400b854 Mon Sep 17 00:00:00 2001 From: Vantz Stockwell Date: Thu, 11 Jun 2026 08:34:18 -0400 Subject: [PATCH] fix(docker): auto-build schema on a fresh DB via docker-entrypoint-initdb.d MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause of 'data lost on every rebuild': nothing created the Postgres schema. TypeORM is synchronize:false, the API container runs no migration step, and there was no init mount — so a fresh pg_data volume came up with ZERO tables (empty/broken DB; the schema had only ever been loaded manually). Mount backend/migrations/*.sql into /docker-entrypoint-initdb.d so Postgres auto-applies the full schema (001..021, plain SQL) ON FIRST INIT ONLY. Existing volumes are untouched (initdb scripts run only on an empty data dir); a fresh volume now self-heals the schema. NOTE: actual row DATA still persists only while the pg_data named volume persists — 'docker compose down' keeps it across 'build --no-cache'; 'down -v' / volume prune is the only thing that wipes it. Co-Authored-By: Claude Opus 4.8 --- docker/docker-compose.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bb4b9ce..088d98d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,6 +8,13 @@ services: POSTGRES_PASSWORD: ${DB_PASSWORD:-corrosion_dev} volumes: - pg_data:/var/lib/postgresql/data + # Auto-build the schema on a FRESH database. Postgres runs these ONLY when + # the data dir is empty (first boot or after a volume reset), so it never + # touches an existing volume — it just makes a fresh DB self-heal: the full + # schema is applied in order from the sqlx migrations (001..NNN), then the + # API's bootstrap seeds the admin. Rebuilds (with the volume kept) are a + # no-op here; the data persists. Only `down -v` / volume prune loses data. + - ../backend/migrations:/docker-entrypoint-initdb.d:ro ports: - "8101:5432" healthcheck: