-- CreateEnum CREATE TYPE "ConsentStatus" AS ENUM ('pending', 'given', 'declined'); -- AlterEnum -- This migration adds more than one value to an enum. -- With PostgreSQL versions 11 and earlier, this is not possible -- in a single migration. This can be worked around by creating -- multiple migrations, each migration adding only one value to -- the enum. ALTER TYPE "AdminAuditAction" ADD VALUE 'consent_override'; ALTER TYPE "AdminAuditAction" ADD VALUE 'consent_rerequested'; ALTER TYPE "AdminAuditAction" ADD VALUE 'medical_list_viewed'; -- AlterTable ALTER TABLE "Attendee" ADD COLUMN "parentEmail" TEXT, ADD COLUMN "parentName" TEXT, ADD COLUMN "parentPhone" TEXT; -- AlterTable ALTER TABLE "Event" ADD COLUMN "consentCollectEmergency" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "consentCollectMedical" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "consentCollectPhoto" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "consentText" TEXT, ADD COLUMN "consentTextVersion" INTEGER NOT NULL DEFAULT 1, ADD COLUMN "requiresParentalConsent" BOOLEAN NOT NULL DEFAULT false; -- CreateTable CREATE TABLE "ConsentRequest" ( "id" TEXT NOT NULL, "attendeeId" TEXT NOT NULL, "eventId" TEXT NOT NULL, "tokenHash" TEXT NOT NULL, "status" "ConsentStatus" NOT NULL DEFAULT 'pending', "textVersion" INTEGER NOT NULL, "consentText" TEXT NOT NULL, "parentName" TEXT, "parentEmail" TEXT, "parentPhone" TEXT, "signedName" TEXT, "ip" TEXT, "device" TEXT, "medical" TEXT, "emergency" TEXT, "photoConsent" BOOLEAN, "respondedAt" TIMESTAMP(3), "lastSentAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "remindersSent" INTEGER NOT NULL DEFAULT 0, "expiresAt" TIMESTAMP(3) NOT NULL, "medicalPurgedAt" TIMESTAMP(3), "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "ConsentRequest_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "ConsentRequest_tokenHash_key" ON "ConsentRequest"("tokenHash"); -- CreateIndex CREATE INDEX "ConsentRequest_attendeeId_createdAt_idx" ON "ConsentRequest"("attendeeId", "createdAt"); -- CreateIndex CREATE INDEX "ConsentRequest_eventId_status_idx" ON "ConsentRequest"("eventId", "status"); -- AddForeignKey ALTER TABLE "ConsentRequest" ADD CONSTRAINT "ConsentRequest_attendeeId_fkey" FOREIGN KEY ("attendeeId") REFERENCES "Attendee"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "ConsentRequest" ADD CONSTRAINT "ConsentRequest_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE CASCADE ON UPDATE CASCADE;