-- AlterTable
ALTER TABLE "public"."Calculation"
ADD COLUMN "title" TEXT NOT NULL DEFAULT 'Untitled Case',
ADD COLUMN "reportToken" TEXT,
ADD COLUMN "metadata" JSONB;

-- Backfill existing records before constraints
UPDATE "public"."Calculation"
SET "reportToken" = md5(random()::text || clock_timestamp()::text || "id")
WHERE "reportToken" IS NULL;

-- Enforce required token and uniqueness
ALTER TABLE "public"."Calculation"
ALTER COLUMN "reportToken" SET NOT NULL;

CREATE UNIQUE INDEX "Calculation_reportToken_key" ON "public"."Calculation"("reportToken");
