-- Per-shipment attachment selection: only checked files are visible to the lab.
CREATE TABLE "lab_case_attachments" (
  "labCaseId" TEXT NOT NULL,
  "attachmentId" TEXT NOT NULL,
  CONSTRAINT "lab_case_attachments_pkey" PRIMARY KEY ("labCaseId", "attachmentId")
);

CREATE INDEX "lab_case_attachments_attachmentId_idx" ON "lab_case_attachments"("attachmentId");

ALTER TABLE "lab_case_attachments"
  ADD CONSTRAINT "lab_case_attachments_labCaseId_fkey"
  FOREIGN KEY ("labCaseId") REFERENCES "lab_cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "lab_case_attachments"
  ADD CONSTRAINT "lab_case_attachments_attachmentId_fkey"
  FOREIGN KEY ("attachmentId") REFERENCES "treatment_detail_attachments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
