fix(db): wait for/retry DB DNS resolution before drizzle-kit migrate (GRO-2163) #161
Reference in New Issue
Block a user
Delete Branch "fix/gro-2163-migrate-pre-dns-wait"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
packages/db/scripts/wait-for-db.mjs— a no-deps Node 22 script that resolves the database hostname derived fromDATABASE_URLvianode:dns.promiseswith exponential backoff (12 attempts, ~30s total) and only exits 0 once a real IP is returned.pre-migrate(andpre-seed/pre-reset) hook in@groombook/dbso pnpm auto-runs it before any data-plane command.pnpm migratestaysdrizzle-kit migrate— the wait is added transparently.groombook/infraflea/GRO-2149-stagger-dns-config) carries the K8s-side defense-in-depth (backoffLimit: 4,dnsConfig.options += ndots:2+ the prior GRO-2149single-request-reopen).Why
The first attempt of a fresh
migrate-schemapod occasionally hits a transient CoreDNS miss (EAI_AGAIN) ongroombook-postgres-rw.<ns>.svc. WithbackoffLimit: 2the retry pod usually wins, but three unlucky attempts in a row tripsBackoffLimitExceeded. Resolving once here, with backoff, removes the dice roll at the source so the first attempt reliably succeeds.Mirrors the belt-and-braces pattern used in GRO-1985 (disable Corepack download fallback): do not try to outsmart CoreDNS, just do not ask
drizzle-kitto do the very first DNS lookup of a freshly-scheduled pod.Test plan
node packages/db/scripts/wait-for-db.mjswithDATABASE_URLset to the live paperclip-pg host resolves on attempt 1 in 7ms (sandbox).pnpm --filter @groombook/db typecheck(no TS change).migrate-schema-b5943fbpod logs for a clean[wait-for-db] ok attempt=1 ...line beforedrizzle-kit migrateoutput.Out of scope
Refs