---
name: database-diagnostics
description: DB-sanity: Drizzle/pooler, schema-checks, system_events. Alleen bestaande scripts en commands.
---

# DATABASE DIAGNOSTICS SUPER-SKILL

“Nuclear Truth” = **PostgreSQL (Supabase)**. Gebruik deze **bestaande** entrypoints (repo-root tenzij anders vermeld).

## Core workflows

### 1. Snelle connectie / sanity
- **Chat migratie 0106** (`visitor_live_snapshot` op `chat_conversations`): `npm run verify:chat-schema-0106` (opt-in; strict: `verify:chat-schema-0106:strict` voor CI)
- **Schema-audit 0140** (ontbrekende `public`-tabellen + `actor_dialects` kolommen): apply `npm run db:apply:0140-schema-audit`, verify `npm run verify:schema-0140` (strict: `verify:schema-0140:strict`)
- **Drizzle smoke (voorbeeld schema)**: `npx tsx scripts/test-db.ts`
- **Snelle DB-check**: `npx tsx scripts/quick-db-check.ts`
- **Schema verkenning**: `npx tsx scripts/check-db-schema.ts` (en varianten zoals `check-db-schema2.ts` indien nodig)
- **`relation "public.…" does not exist` tijdens migratie:** vóór “verkeerde URL” → **`.cursor/rules/100-SUPABASE-ARCHITECTURE.mdc` §3c** (read-only `to_regclass` + sibling op **dezelfde** `DATABASE_URL`).

### 2. Forensische sanity (app workspace)
- **Lightweight check (retry logic)**: vanuit `apps/web`: `npm run audit:forensic` → `scripts/quick-check.ts`

### 3. Orders / business checks (voorbeelden)
- `npx tsx scripts/check-db-orders.ts`  -  pas toe in context van de vraag

### 4. System events
- `npx tsx scripts/query-system-events-schema.ts`
- `npx tsx scripts/query-system-events-live.ts`
- `npx tsx scripts/query-system-events-1h.ts` / `query-system-events-5h.ts`
- `npx tsx scripts/query-critical.ts` / `query-real-errors.ts`

## Niet meer in repo (niet verwijzen)
- `scripts/core/diagnostics/*`, `integrity-handshake.ts`, `lexicon-handshake.ts`, `forensic-atomic-truth-scan.ts`, `forensic-data-audit.ts`  -  **ontbreken**. Vervang door bovenstaande of nieuw script.

## Verplichte richtlijnen
- **Bassie-protocol**: pooler/timeouts, SSL  -  zie `.cursorrules` / `100-SUPABASE-ARCHITECTURE.mdc`.
- **Snake case** in DB/API: `200-CODE-INTEGRITY.mdc`.
- Managed door **Chris** en **Bassie**.
