Files
dyolink/backend/prisma/migrations/20260707140000_unify_lab_case_comments/migration.sql

24 lines
519 B
SQL

-- 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";