From 4413295b2755c8251b77367d333cfa1b66e21217 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 24 Sep 2025 08:20:25 +0530 Subject: [PATCH] feat: Add spam block schema and migration (#23996) * schema * fix migration * -- * optional org * -- * remove prisma level relation * -- * rename * remove redundant key * -- --- .../migration.sql | 52 +++++++++++++++++++ packages/prisma/schema.prisma | 39 +++++++++++--- 2 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 packages/prisma/migrations/20250923082416_add_spam_block/migration.sql diff --git a/packages/prisma/migrations/20250923082416_add_spam_block/migration.sql b/packages/prisma/migrations/20250923082416_add_spam_block/migration.sql new file mode 100644 index 0000000000..c8814cae4e --- /dev/null +++ b/packages/prisma/migrations/20250923082416_add_spam_block/migration.sql @@ -0,0 +1,52 @@ +/* + Warnings: + + - A unique constraint covering the columns `[type,value,organizationId]` on the table `Watchlist` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateEnum +CREATE TYPE "WatchlistAction" AS ENUM ('REPORT', 'BLOCK'); + +-- DropIndex +DROP INDEX "Watchlist_type_value_idx"; + +-- DropIndex +DROP INDEX "Watchlist_type_value_key"; + +-- AlterTable +ALTER TABLE "Watchlist" ADD COLUMN "action" "WatchlistAction" NOT NULL DEFAULT 'REPORT', +ADD COLUMN "organizationId" INTEGER; + +-- CreateTable +CREATE TABLE "BlockedBookingLog" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "eventTypeId" INTEGER, + "organizationId" INTEGER, + "bookingData" JSONB, + "watchlistId" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "BlockedBookingLog_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "BlockedBookingLog_organizationId_createdAt_idx" ON "BlockedBookingLog"("organizationId", "createdAt"); + +-- CreateIndex +CREATE INDEX "BlockedBookingLog_email_idx" ON "BlockedBookingLog"("email"); + +-- CreateIndex +CREATE INDEX "BlockedBookingLog_watchlistId_idx" ON "BlockedBookingLog"("watchlistId"); + +-- CreateIndex +CREATE INDEX "Watchlist_type_value_organizationId_action_idx" ON "Watchlist"("type", "value", "organizationId", "action"); + +-- CreateIndex +CREATE UNIQUE INDEX "Watchlist_type_value_organizationId_key" ON "Watchlist"("type","value","organizationId"); + +-- CreateIndex +-- Enforce uniqueness for global entries (organizationId IS NULL) +CREATE UNIQUE INDEX "Watchlist_type_value_global_key" + ON "Watchlist"("type","value") + WHERE "organizationId" IS NULL; diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index 6f08cb9cd6..71a60d98d6 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -2248,22 +2248,47 @@ enum WatchlistSeverity { CRITICAL } +enum WatchlistAction { + REPORT + BLOCK +} + model Watchlist { - id String @id @unique @default(cuid()) - type WatchlistType - // The identifier of the Watchlisted entity (email or domain) + id String @id @unique @default(cuid()) + type WatchlistType + value String description String? + + organizationId Int? + + action WatchlistAction @default(REPORT) + severity WatchlistSeverity @default(LOW) createdAt DateTime @default(now()) - createdBy User @relation("CreatedWatchlists", onDelete: Cascade, fields: [createdById], references: [id]) + createdBy User @relation("CreatedWatchlists", onDelete: SetNull, fields: [createdById], references: [id]) createdById Int updatedAt DateTime @updatedAt updatedBy User? @relation("UpdatedWatchlists", onDelete: SetNull, fields: [updatedById], references: [id]) updatedById Int? - severity WatchlistSeverity @default(LOW) - @@unique([type, value]) - @@index([type, value]) + @@unique([type, value, organizationId]) + @@index([type, value, organizationId, action]) +} + +model BlockedBookingLog { + id String @id @default(uuid()) + email String + eventTypeId Int? + + organizationId Int? + + bookingData Json? + createdAt DateTime @default(now()) + watchlistId String? + + @@index([organizationId, createdAt]) + @@index([email]) + @@index([watchlistId]) } enum BillingPeriod {