papertrail/db/migrations/0067_provenance-chain.sql
caelum0x 869d44f1ec feat: Next tier — contradiction atlas, subgroup+pub-bias hardening, RAG-fusion+sufficiency, chain of custody
- Contradiction Atlas: deterministic conflict explainer (population/dose/tissue/follow-up) over Valsci
  mixed verdicts + INDRA belief; backend/engines/Valsci/papertrail_conflict.py +
  backend/engines/indra/grounding_hook.py (in-place); /api/verify/contradiction-resolve + /console/contradiction
- Verification hardening: subgroup-cited-as-primary check wired into structuredVerification; publication-bias
  (Egger + trim-and-fill) auto-downgrades GRADE one step; /api/verify/subgroup-check + /api/evidence-report/meta-bias-analysis
- RAG-fusion + evidence-sufficiency: backend/engines/R2R/papertrail_rag_fusion.py (in-place); ragFusionRetrieve +
  evidenceSufficiency; /api/research/expand-query
- Immutable chain of custody: migration 0067 evidence_source_versions; lib/provenance/chainOfCustody.ts
  (sha256 over provenance tuple, re-grounded spans); anchorChainOfCustody into WORM chain;
  /api/audit-chain/verification/[id] + /console/audit/custody (in-browser hash verify)

All edits to existing core files (structuredVerification/grade/hybrid/evidencePipeline/chain) surgical + additive;
tsc + build green; 0067 applied to Neon.
2026-07-11 00:58:44 +03:00

27 lines
1.2 KiB
SQL

-- Immutable provenance / snapshot versioning (21 CFR Part 11-grade chain of custody).
--
-- A single cached `source` (in db/migrations.sql) holds only its LATEST fetched
-- raw_text. For an auditable provenance trail we must be able to reconstruct the
-- EXACT version of a source that was in effect when a given verification quoted it.
-- `evidence_source_versions` is an append-only snapshot ledger: each row records a
-- content-addressed snapshot of a source (its content_hash) alongside the external
-- identifiers (doi/pmid), the upstream source_version label, and when the snapshot
-- was taken. buildChainOfCustody() joins a verification's grounded spans to the
-- source-version that was current at export time.
--
-- Idempotent — safe to run repeatedly.
create table if not exists evidence_source_versions (
id uuid primary key default gen_random_uuid(),
source_id uuid not null references sources(id) on delete cascade,
source_version text,
snapshot_date timestamptz,
doi text,
pmid text,
content_hash text,
recorded_at timestamptz default now()
);
create index if not exists evidence_source_versions_source_id_idx
on evidence_source_versions (source_id);