feat: Add spam block schema and migration (#23996)

* schema

* fix migration

* --

* optional org

* --

* remove prisma level relation

* --

* rename

* remove redundant key

* --
This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2025-09-24 03:50:25 +01:00
1 parent bcc433ba9a
commit 4413295b27
2 files changed
+84 -7

No files matched your search

@@ -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;
+32 -7
View File
@@ -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 {