Skip to content

Commit 4413295

Browse files
feat: Add spam block schema and migration (calcom#23996)
* schema * fix migration * -- * optional org * -- * remove prisma level relation * -- * rename * remove redundant key * --
1 parent bcc433b commit 4413295

2 files changed

Lines changed: 84 additions & 7 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Warnings:
3+
4+
- 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.
5+
6+
*/
7+
-- CreateEnum
8+
CREATE TYPE "WatchlistAction" AS ENUM ('REPORT', 'BLOCK');
9+
10+
-- DropIndex
11+
DROP INDEX "Watchlist_type_value_idx";
12+
13+
-- DropIndex
14+
DROP INDEX "Watchlist_type_value_key";
15+
16+
-- AlterTable
17+
ALTER TABLE "Watchlist" ADD COLUMN "action" "WatchlistAction" NOT NULL DEFAULT 'REPORT',
18+
ADD COLUMN "organizationId" INTEGER;
19+
20+
-- CreateTable
21+
CREATE TABLE "BlockedBookingLog" (
22+
"id" TEXT NOT NULL,
23+
"email" TEXT NOT NULL,
24+
"eventTypeId" INTEGER,
25+
"organizationId" INTEGER,
26+
"bookingData" JSONB,
27+
"watchlistId" TEXT,
28+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
29+
30+
CONSTRAINT "BlockedBookingLog_pkey" PRIMARY KEY ("id")
31+
);
32+
33+
-- CreateIndex
34+
CREATE INDEX "BlockedBookingLog_organizationId_createdAt_idx" ON "BlockedBookingLog"("organizationId", "createdAt");
35+
36+
-- CreateIndex
37+
CREATE INDEX "BlockedBookingLog_email_idx" ON "BlockedBookingLog"("email");
38+
39+
-- CreateIndex
40+
CREATE INDEX "BlockedBookingLog_watchlistId_idx" ON "BlockedBookingLog"("watchlistId");
41+
42+
-- CreateIndex
43+
CREATE INDEX "Watchlist_type_value_organizationId_action_idx" ON "Watchlist"("type", "value", "organizationId", "action");
44+
45+
-- CreateIndex
46+
CREATE UNIQUE INDEX "Watchlist_type_value_organizationId_key" ON "Watchlist"("type","value","organizationId");
47+
48+
-- CreateIndex
49+
-- Enforce uniqueness for global entries (organizationId IS NULL)
50+
CREATE UNIQUE INDEX "Watchlist_type_value_global_key"
51+
ON "Watchlist"("type","value")
52+
WHERE "organizationId" IS NULL;

packages/prisma/schema.prisma

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,22 +2248,47 @@ enum WatchlistSeverity {
22482248
CRITICAL
22492249
}
22502250

2251+
enum WatchlistAction {
2252+
REPORT
2253+
BLOCK
2254+
}
2255+
22512256
model Watchlist {
2252-
id String @id @unique @default(cuid())
2253-
type WatchlistType
2254-
// The identifier of the Watchlisted entity (email or domain)
2257+
id String @id @unique @default(cuid())
2258+
type WatchlistType
2259+
22552260
value String
22562261
description String?
2262+
2263+
organizationId Int?
2264+
2265+
action WatchlistAction @default(REPORT)
2266+
severity WatchlistSeverity @default(LOW)
22572267
createdAt DateTime @default(now())
2258-
createdBy User @relation("CreatedWatchlists", onDelete: Cascade, fields: [createdById], references: [id])
2268+
createdBy User @relation("CreatedWatchlists", onDelete: SetNull, fields: [createdById], references: [id])
22592269
createdById Int
22602270
updatedAt DateTime @updatedAt
22612271
updatedBy User? @relation("UpdatedWatchlists", onDelete: SetNull, fields: [updatedById], references: [id])
22622272
updatedById Int?
2263-
severity WatchlistSeverity @default(LOW)
22642273
2265-
@@unique([type, value])
2266-
@@index([type, value])
2274+
@@unique([type, value, organizationId])
2275+
@@index([type, value, organizationId, action])
2276+
}
2277+
2278+
model BlockedBookingLog {
2279+
id String @id @default(uuid())
2280+
email String
2281+
eventTypeId Int?
2282+
2283+
organizationId Int?
2284+
2285+
bookingData Json?
2286+
createdAt DateTime @default(now())
2287+
watchlistId String?
2288+
2289+
@@index([organizationId, createdAt])
2290+
@@index([email])
2291+
@@index([watchlistId])
22672292
}
22682293

22692294
enum BillingPeriod {

0 commit comments

Comments
 (0)