papertrail/db/migrations/0070_data-governance.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

21 lines
825 B
SQL

-- Data governance: legal holds (litigation / regulatory preservation).
-- A legal hold pins a data SUBJECT (identified by a stable string, e.g. an email)
-- so the retention-purge worker must NOT delete or anonymize their data while the
-- hold is active. Idempotent — safe to run repeatedly.
create table if not exists legal_holds (
id uuid primary key default gen_random_uuid(),
org_id uuid not null references orgs(id) on delete cascade,
subject text not null,
reason text,
active boolean not null default true,
placed_by uuid,
placed_at timestamptz default now(),
released_at timestamptz
);
-- The retention worker consults this predicate with (org_id, active) as the hot
-- path, so index on exactly that pair.
create index if not exists legal_holds_org_active_idx
on legal_holds(org_id, active);