-- CreateEnum
CREATE TYPE "MemberCampaignNotificationModelName" AS ENUM ('MemberCampaignNotification');

-- CreateTable
CREATE TABLE "MemberCampaignNotification" (
    "modelName" "MemberCampaignNotificationModelName" NOT NULL DEFAULT 'MemberCampaignNotification',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "memberId" UUID NOT NULL,
    "notificationId" UUID NOT NULL,
    "sentAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "type" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,

    CONSTRAINT "MemberCampaignNotification_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "MemberCampaignNotification" ADD CONSTRAINT "MemberCampaignNotification_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberCampaignNotification" ADD CONSTRAINT "MemberCampaignNotification_notificationId_fkey" FOREIGN KEY ("notificationId") REFERENCES "Notification"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- Unsubscribe any existing members
UPDATE "Member"
SET "unsubscribedFromMarketingAt" = now();
