Files
2026-11-16 17:26:44 -08:00

22 lines
1.2 KiB
SQL

-- Injection → adoption: record which injected claims the drafter actually cited.
--
-- Hand-written (same convention as 0003): two additive nullable columns on an
-- existing table, which drizzle-kit would render identically but with a
-- generated name that says nothing about why.
--
-- NULL vs '[]' is load-bearing and must not be collapsed to a default:
-- NULL — nobody reported. Either the run predates the citation contract or
-- the node's bundle is older than it. "Unknown", not "zero".
-- '[]' — the drafter reported and adopted nothing. That is a real,
-- actionable measurement (retrieval returned junk).
-- Giving this column a DEFAULT '[]' would silently turn every historical row
-- into "adopted nothing" and make the first weeks of hit-rate data a lie.
ALTER TABLE "kb_injections" ADD COLUMN IF NOT EXISTS "used_claim_ids" text;
ALTER TABLE "kb_injections" ADD COLUMN IF NOT EXISTS "used_at" bigint;
-- recordKbUsage looks up the newest injection for (target_kind, target_id, stage)
-- on every citation report, and the drawer reads by (target_kind, target_id).
CREATE INDEX IF NOT EXISTS "kb_injections_target_idx"
ON "kb_injections" ("target_kind", "target_id", "ts" DESC);