papertrail/db/migrations/0059_lab-notebook.sql
caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

39 lines
1.7 KiB
SQL

-- Lab Notebook Companion. A bench scientist pastes rough notes or a voice-memo
-- transcript; Claude structures them into a reproducible, searchable experiment
-- record (protocol steps, reagents, samples, equipment, observations, outcomes,
-- entities) where every quoted field is grounded to a verbatim span of the raw
-- note. This table is the org-scoped store of those saved records.
--
-- Trust/grounding constraint (enforced in lib/labNotebook/structure.ts, mirrored
-- here as documentation): the `structured` JSON only ever contains source_span
-- values that are verbatim substrings of `raw_notes` — ungroundable items are
-- dropped before a record is ever saved, so this table never holds an unsourced
-- claim about the note.
--
-- Full-text search: a stored generated tsvector over title + raw_notes, so the
-- saved-experiment list can be searched with websearch_to_tsquery without a
-- runtime to_tsvector on every row.
--
-- Idempotent — safe to run repeatedly. org_id on the table; uuid pk; created_at.
create table if not exists lab_experiments (
id uuid primary key default gen_random_uuid(),
org_id uuid not null references orgs(id) on delete cascade,
created_by uuid,
title text not null,
experiment_date date,
raw_notes text not null,
structured jsonb not null,
tags text[] not null default '{}',
created_at timestamptz not null default now(),
search tsvector generated always as (
to_tsvector('english', coalesce(title, '') || ' ' || coalesce(raw_notes, ''))
) stored
);
create index if not exists lab_experiments_search_idx
on lab_experiments using gin (search);
create index if not exists lab_experiments_org_created_idx
on lab_experiments (org_id, created_at desc);