-- Migrate legacy single-string labComment into per-case comment rows, then drop the column.

INSERT INTO "lab_case_comments" (
  "id",
  "labCaseId",
  "authorSide",
  "body",
  "visibleToClinic",
  "createdAt",
  "updatedAt"
)
SELECT
  gen_random_uuid()::text,
  lc."id",
  'CLINIC'::"LabCaseCommentSide",
  trim(lc."labComment"),
  true,
  COALESCE(lc."sentAt", NOW()),
  NOW()
FROM "lab_cases" lc
WHERE lc."labComment" IS NOT NULL AND trim(lc."labComment") <> '';

ALTER TABLE "lab_cases" DROP COLUMN "labComment";
