feat(api): add DB-touching /api/readyz so schema loss cannot hide behind /health (GRO-2678) #231

Merged
Flea Flicker merged 2 commits from feat/gro-2678-readyz-db-check into dev 2026-08-09 09:11:35 +00:00
Member

Summary

Follow-up to GRO-2678 / GRO-2687.

PROD's groombook DB schema was dropped and the outage stayed hidden for ~43h because /health and /api/health return {"status":"ok"} without touching the database. This PR adds a separate, DB-touching endpoint that the monitoring layer can consume.

CTO decision (unchanged): /health and /api/health remain DB-less — they back K8s liveness/readiness probes and intentionally must not cycle pods on transient DB blips.

Changes

  • src/index.ts — registers GET /api/readyz after the existing health routes (before authMiddleware)
    • Runs getDb().select({ id: staff.id }).from(staff).limit(1) inside try/catch
    • Success → 200 {"status":"ready"}
    • DB error → 503 {"status":"degraded","check":"db"} (raw driver error is console.error'd, never leaked to body)
  • src/__tests__/readyz.test.ts — unit tests: mock getDb to (a) resolve → assert 200/ready, (b) throw → assert 503/degraded; also asserts raw SQL text does not appear in the 503 body
  • UAT_PLAYBOOK.md — updated §4.0 Health Check with TC-API-0.2 and TC-API-0.3

Acceptance criteria

  • GET /api/readyz → 200 {"status":"ready"} when DB query succeeds
  • GET /api/readyz → 503 {"status":"degraded","check":"db"} when query throws
  • /health and /api/health are unchanged
  • Response body never contains raw SQL / driver error text
  • New unit tests pass; all 689 existing tests green; typecheck clean

UAT Playbook

Updated UAT_PLAYBOOK.md §4.0 — added TC-API-0.2 (200 ready) and TC-API-0.3 (body safety check).

cc @cpfarhood

## Summary Follow-up to [GRO-2678](/GRO/issues/GRO-2678) / [GRO-2687](/GRO/issues/GRO-2687). PROD's `groombook` DB schema was dropped and the outage stayed hidden for ~43h because `/health` and `/api/health` return `{"status":"ok"}` without touching the database. This PR adds a **separate, DB-touching** endpoint that the monitoring layer can consume. **CTO decision (unchanged):** `/health` and `/api/health` remain DB-less — they back K8s liveness/readiness probes and intentionally must not cycle pods on transient DB blips. ## Changes - **`src/index.ts`** — registers `GET /api/readyz` after the existing health routes (before `authMiddleware`) - Runs `getDb().select({ id: staff.id }).from(staff).limit(1)` inside try/catch - Success → `200 {"status":"ready"}` - DB error → `503 {"status":"degraded","check":"db"}` (raw driver error is `console.error`'d, never leaked to body) - **`src/__tests__/readyz.test.ts`** — unit tests: mock `getDb` to (a) resolve → assert 200/`ready`, (b) throw → assert 503/`degraded`; also asserts raw SQL text does not appear in the 503 body - **`UAT_PLAYBOOK.md`** — updated §4.0 Health Check with TC-API-0.2 and TC-API-0.3 ## Acceptance criteria - [x] `GET /api/readyz` → 200 `{"status":"ready"}` when DB query succeeds - [x] `GET /api/readyz` → 503 `{"status":"degraded","check":"db"}` when query throws - [x] `/health` and `/api/health` are unchanged - [x] Response body never contains raw SQL / driver error text - [x] New unit tests pass; all 689 existing tests green; typecheck clean ## UAT Playbook Updated `UAT_PLAYBOOK.md` §4.0 — added TC-API-0.2 (200 ready) and TC-API-0.3 (body safety check). cc @cpfarhood
Flea Flicker added 1 commit 2026-08-09 09:02:58 +00:00
feat(api): add DB-touching /api/readyz so schema loss cannot hide behind /health (GRO-2678)
CI / Test (pull_request) Failing after 30s
CI / Lint & Typecheck (pull_request) Successful in 2m31s
CI / Build & Push Docker Images (pull_request) Has been skipped
f54a13fc8a
- 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>
Flea Flicker added 1 commit 2026-08-09 09:10:12 +00:00
ci: retrigger after seed-image registry push flake
CI / Lint & Typecheck (pull_request) Successful in 17s
CI / Test (pull_request) Successful in 19s
CI / Build & Push Docker Images (pull_request) Successful in 46s
6148ae6439
Co-Authored-By: Paperclip <noreply@paperclip.ing>
Flea Flicker merged commit a164c24e8e into dev 2026-08-09 09:11:35 +00:00
Flea Flicker deleted branch feat/gro-2678-readyz-db-check 2026-08-09 09:11:36 +00:00
Sign in to join this conversation.