papertrail/db/migrations/0069_living-evidence.sql
caelum0x 91fe8978d8 feat: enterprise + evidence depth — living evidence, verdict fragility, gated audit export, DSAR + legal hold
Evidence:
- Living Evidence Monitoring: deterministic cumulative meta-analysis (re-pool in time order, first-significant
  + would-a-new-study-flip); monitors + events (0069); backend/engines/pyalex citation-velocity (in-place);
  /api/evidence/living(+/assess) + /console/living-evidence
- Verdict Fragility: Walsh Fragility Index (exhaustive Fisher-exact reassignment) + meta leave-one-out
  robustness + required-information-size; /api/evidence/fragility + /console/fragility

Enterprise:
- Immutable audit export (Enterprise-tier gated): verifyChain + per-entry integrity proofs + export_hash;
  FIRST real requireFeature enforcement -> UpgradeRequired 402 with upgrade CTA; /api/enterprise/audit-export
- Data governance: legal holds (block retention purge) + DSAR export (no secrets/hashes) (0070);
  /api/governance/legal-hold + /api/governance/dsar + /console/governance/data

All numeric/verdict paths deterministic (no LLM); org-scoped; tsc + build green; 0069/0070 applied to Neon.
2026-07-11 03:25:07 +03:00

39 lines
1.6 KiB
SQL

-- Living evidence monitoring. A monitor watches a topic/claim; when NEW evidence
-- lands, PaperTrail deterministically re-pools the accumulating studies (cumulative
-- meta-analysis) and flags whether the pooled verdict would FLIP (direction or
-- significance). No LLM decides the verdict — the flip is decided by the same
-- inverse-variance closed forms as lib/metaAnalysis.ts.
--
-- Governance constraint (enforced in lib/livingEvidence/monitor.ts, mirrored here
-- as documentation): stored jsonb (baseline, event detail) carries only numeric
-- estimates / ids / counts — never claim or source raw text — so a monitor's
-- history can be exported to a regulated buyer without leaking claim content.
--
-- Idempotent — safe to run repeatedly. org_id on the monitor table; uuid pk;
-- created_at. Events cascade with their monitor.
create table if not exists living_evidence_monitors (
id uuid primary key default gen_random_uuid(),
org_id uuid not null references orgs(id) on delete cascade,
topic text not null,
query text,
baseline jsonb,
last_checked_at timestamptz,
created_by uuid,
created_at timestamptz not null default now()
);
create table if not exists living_evidence_events (
id uuid primary key default gen_random_uuid(),
monitor_id uuid not null references living_evidence_monitors(id) on delete cascade,
kind text,
detail jsonb,
created_at timestamptz not null default now()
);
create index if not exists living_evidence_monitors_org_created_idx
on living_evidence_monitors(org_id, created_at desc);
create index if not exists living_evidence_events_monitor_idx
on living_evidence_events(monitor_id, created_at desc);