feat(api): add DB-touching /api/readyz so schema loss cannot hide behind /health (GRO-2678) #231
Reference in New Issue
Block a user
Delete Branch "feat/gro-2678-readyz-db-check"
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
Follow-up to GRO-2678 / GRO-2687.
PROD's
groombookDB schema was dropped and the outage stayed hidden for ~43h because/healthand/api/healthreturn{"status":"ok"}without touching the database. This PR adds a separate, DB-touching endpoint that the monitoring layer can consume.CTO decision (unchanged):
/healthand/api/healthremain DB-less — they back K8s liveness/readiness probes and intentionally must not cycle pods on transient DB blips.Changes
src/index.ts— registersGET /api/readyzafter the existing health routes (beforeauthMiddleware)getDb().select({ id: staff.id }).from(staff).limit(1)inside try/catch200 {"status":"ready"}503 {"status":"degraded","check":"db"}(raw driver error isconsole.error'd, never leaked to body)src/__tests__/readyz.test.ts— unit tests: mockgetDbto (a) resolve → assert 200/ready, (b) throw → assert 503/degraded; also asserts raw SQL text does not appear in the 503 bodyUAT_PLAYBOOK.md— updated §4.0 Health Check with TC-API-0.2 and TC-API-0.3Acceptance criteria
GET /api/readyz→ 200{"status":"ready"}when DB query succeedsGET /api/readyz→ 503{"status":"degraded","check":"db"}when query throws/healthand/api/healthare unchangedUAT Playbook
Updated
UAT_PLAYBOOK.md§4.0 — added TC-API-0.2 (200 ready) and TC-API-0.3 (body safety check).cc @cpfarhood
- Register GET /api/readyz after /api/health in src/index.ts (before authMiddleware) - Runs `getDb().select({id: staff.id}).from(staff).limit(1)` inside try/catch - Success → 200 {"status":"ready"}; failure → 503 {"status":"degraded","check":"db"} - Raw driver error is console.error'd but never leaked to the response body - /health and /api/health are unchanged (K8s probes remain DB-less per CTO decision) - New unit tests: mock getDb to resolve → assert 200/ready; throw → assert 503/degraded - Updated UAT_PLAYBOOK.md §4.0 with TC-API-0.2 and TC-API-0.3 Co-Authored-By: Paperclip <noreply@paperclip.ing>