-- Move the "important" flag from individual tasks to the case as a whole.
ALTER TABLE "lab_cases" ADD COLUMN "isImportant" BOOLEAN NOT NULL DEFAULT false;

-- Carry over existing importance: a case is important if any of its tasks were.
UPDATE "lab_cases" lc
SET "isImportant" = true
WHERE EXISTS (
  SELECT 1 FROM "lab_case_tasks" t
  WHERE t."labCaseId" = lc."id" AND t."isImportant" = true
);

DROP INDEX IF EXISTS "lab_case_tasks_labCaseId_isImportant_idx";
ALTER TABLE "lab_case_tasks" DROP COLUMN "isImportant";
