# Pre-existing Infra Gaps — `@zync/db` (NOT part of the Morning Payments epic)

**Date:** 2026-06-09
**Status:** Both DEFERRED — neither blocks the payments epic. Recorded so the "fix before Wave 4"
note in the Wave 1 verification record is explicitly overridden (its real purpose — a clean
verification baseline — is already met by diffing against the pre-existing error set).

These are ancient, epic-unrelated debt in the `@zync/db` query layer. The payments epic verifies by
diffing against the baseline error set (held for 3 waves), so a green baseline is hygiene, not a gate.

---

## Gap A — `@zync/db` typecheck reds (≈40, whole query layer) — DEFER as its own spec-gap item

**Symptom:** `tsc --noEmit` in `packages/db` reports ~40 `TS2591 Cannot find name 'Buffer'/'process'`
and `TS2307 Cannot find module 'node:crypto'` across audit-list, contractors, customers, customer-dedup,
dashboard, data-export, einvoice, expense-*, invoice-adapters, invoices, marketing, projects, receipts,
support, task-*, tasks, payment-gateways(59), drizzle.config.ts. **None are payments files** — all are
the pre-existing query layer.

**Root cause:** `packages/db/tsconfig.json` sets `"types": ["@cloudflare/workers-types"]`, which REPLACES
the default type roots and excludes `@types/node`. Yet those query files use `Buffer` / `process` /
`node:crypto` (Node APIs, runnable in the Worker only under the `nodejs_compat` flag).

**Why NOT fixed here — it encodes an architecture decision:** the project rule is "Workers runtime =
Web Crypto only." This gap is the tension between that rule and 40 files on Node crypto. Resolving it
is a one-way choice, NOT a neutral one-liner:
  - **(a)** add `"node"` to the tsconfig `types` array (+ ensure `@types/node`) — declares the Node
    usage legitimate under `nodejs_compat`; OR
  - **(b)** migrate the 40 files off `Buffer`/`node:crypto` to Web Crypto — upholds the Workers-pure rule.
Per CLAUDE.md, architecture/spec calls route through the high-reasoning layer + user, never an in-flight
implementing commit. So this is a standalone spec-gap-marathon item, escalated to the user when chosen —
not folded into payments.

**To strengthen the Wave-N baseline without deciding:** capture the exact baseline error set
(`file:line`) once and diff precisely against it per wave.

---

## Gap B — missing drizzle snapshots 0033–0046 — NOT APPLICABLE (close)

**Symptom:** `migrations/meta/` has snapshots only through `0032_snapshot.json`; migrations 0033–0046
(journal idx 33–46) have none. 48 `.sql` / 47 journal entries / 27 snapshots.

**Finding — migrations are hand-written, `drizzle generate` is not in the workflow:** 0045 and 0046
carry human descriptive comments (`-- payment-gateway-adapters (morning epic A wave 1)`), bespoke
ALTER/UPDATE/RENAME logic, and manually-placed `--> statement-breakpoint` markers; there is also a
timestamped seed migration (`20260601120000_seed_zapier_make_oauth_clients.sql`). The team authors SQL
by hand. The missing snapshots are therefore **vestigial** — nothing consumes them.

**Do NOT "fix" by running `drizzle generate`:** against the stale 0032 baseline it would emit a giant
bogus migration. Leaving `meta/` untouched is correct. Only a focused, hand-built snapshot-replay task
would be the right fix, and only if `drizzle generate` is ever adopted — which it currently is not.

**Resolution:** closed as not-applicable.
