fix(docker): auto-build schema on a fresh DB via docker-entrypoint-initdb.d
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user