Files
MOPC-Portal/prisma/migrations/20260203220000_add_in_app_notifications/migration.sql
Matt e37154d812 Make migrations idempotent and add missing tables
- Make all pending migrations idempotent (safe to re-run)
- Disable decouple_projects_from_rounds migration (schema not changed)
- Add ProjectTag table for AI tagging
- Add AssignmentJob table for AI assignment progress

On server deployment, run: npx prisma migrate deploy

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 11:09:37 +01:00

54 lines
2.1 KiB
SQL

-- CreateTable
CREATE TABLE IF NOT EXISTS "InAppNotification" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"type" TEXT NOT NULL,
"priority" TEXT NOT NULL DEFAULT 'normal',
"icon" TEXT,
"title" TEXT NOT NULL,
"message" TEXT NOT NULL,
"linkUrl" TEXT,
"linkLabel" TEXT,
"metadata" JSONB,
"groupKey" TEXT,
"isRead" BOOLEAN NOT NULL DEFAULT false,
"readAt" TIMESTAMP(3),
"expiresAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "InAppNotification_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE IF NOT EXISTS "NotificationEmailSetting" (
"id" TEXT NOT NULL,
"notificationType" TEXT NOT NULL,
"category" TEXT NOT NULL,
"label" TEXT NOT NULL,
"description" TEXT,
"sendEmail" BOOLEAN NOT NULL DEFAULT true,
"emailSubject" TEXT,
"emailTemplate" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedById" TEXT,
CONSTRAINT "NotificationEmailSetting_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX IF NOT EXISTS "InAppNotification_userId_isRead_idx" ON "InAppNotification"("userId", "isRead");
CREATE INDEX IF NOT EXISTS "InAppNotification_userId_createdAt_idx" ON "InAppNotification"("userId", "createdAt");
CREATE INDEX IF NOT EXISTS "InAppNotification_groupKey_idx" ON "InAppNotification"("groupKey");
CREATE UNIQUE INDEX IF NOT EXISTS "NotificationEmailSetting_notificationType_key" ON "NotificationEmailSetting"("notificationType");
CREATE INDEX IF NOT EXISTS "NotificationEmailSetting_category_idx" ON "NotificationEmailSetting"("category");
-- AddForeignKey
DO $$ BEGIN
ALTER TABLE "InAppNotification" ADD CONSTRAINT "InAppNotification_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
DO $$ BEGIN
ALTER TABLE "NotificationEmailSetting" ADD CONSTRAINT "NotificationEmailSetting_updatedById_fkey" FOREIGN KEY ("updatedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
EXCEPTION WHEN duplicate_object THEN NULL; END $$;