chore: Watchlist schema update#24246
Conversation
WalkthroughAdds a new enum Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (3)
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql (2)
61-69: Consider auto-updating lastUpdatedAt at DB level.If app forgets to set it, it will drift. Add an UPDATE trigger.
-- Optional helper to keep lastUpdatedAt current CREATE OR REPLACE FUNCTION set_watchlist_last_updated() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN NEW."lastUpdatedAt" := CURRENT_TIMESTAMP; RETURN NEW; END$$; DROP TRIGGER IF EXISTS watchlist_last_updated_trg ON "Watchlist"; CREATE TRIGGER watchlist_last_updated_trg BEFORE UPDATE ON "Watchlist" FOR EACH ROW EXECUTE FUNCTION set_watchlist_last_updated();
92-92: Redundant unique index on primary key."WatchlistAudit_id_key" duplicates the PK. Drop this line to avoid unnecessary index bloat.
-CREATE UNIQUE INDEX "WatchlistAudit_id_key" ON "WatchlistAudit"("id");packages/prisma/schema.prisma (1)
2281-2294: Watchlist model: add update semantics and validate org/global relation.
- lastUpdatedAt isn’t @updatedat; consider using @updatedat for auto-update or ensure app sets it.
- organizationId has no relation; consider linking to Team to enforce integrity.
model Watchlist { id String @id @default(uuid()) @db.Uuid type WatchlistType value String description String? isGlobal Boolean @default(false) - organizationId Int? + organizationId Int? + // Optional: enforce referential integrity at Prisma level + // organization Team? @relation(fields: [organizationId], references: [id], onDelete: SetNull) action WatchlistAction @default(REPORT) source WatchlistSource @default(MANUAL) - lastUpdatedAt DateTime @default(now()) + lastUpdatedAt DateTime @default(now()) + // Optional: prefer @updatedAt if DB trigger is not used + // lastUpdatedAt DateTime @updatedAt @@unique([type, value, organizationId]) @@index([type, value, organizationId, action]) }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql(1 hunks)packages/prisma/schema.prisma(1 hunks)
🔇 Additional comments (5)
packages/prisma/schema.prisma (3)
2276-2279: WatchlistSource enum — LGTM.Defaults and values align with the migration.
2273-2274: Enum value ALERT added — looks good.
No switch/case references found in TS; manually verify any code paths handling WatchlistAction (JS/TS/other) include the new ALERT value.
2296-2298: Prisma UUIDv7 Support: Prisma supports @default(uuid(7)) as of version 5.18.0; ensure your project uses Prisma ≥ 5.18.0 or fall back to @default(uuid()) or app‐generated IDs. Applies to lines 2296–2298 and 2313–2314.packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql (2)
23-37: No additional FKs referencing Watchlist.id
Only createdBy/updatedBy constraints are dropped; no other references exist.
70-77: BlockedBookingLog removal verified: no references found outside migrations; safe to drop.
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Show resolved
Hide resolved
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Outdated
Show resolved
Hide resolved
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
packages/features/watchlist/watchlist.repository.ts (3)
12-19: Add explicitselectto the Prisma query.The query returns all fields from the
Watchlisttable. Per coding guidelines, Prisma queries should only select the data you need usingselectrather than returning entire records.As per coding guidelines, consider specifying only the required fields:
const emailInWatchlist = await db.watchlist.findFirst({ where: { OR: [ { type: WatchlistType.EMAIL, value: email }, { type: WatchlistType.DOMAIN, value: domain }, ], }, + select: { + id: true, + type: true, + value: true, + // Add other fields as needed by callers + }, });
29-34: Add explicitselectto the Prisma query.This query also returns all fields from the
Watchlisttable. Apply the same pattern as suggested forgetBlockedEmailInWatchlistto select only required fields.As per coding guidelines:
const domainInWatchWatchlist = await db.watchlist.findFirst({ where: { type: WatchlistType.DOMAIN, value: emailDomain, }, + select: { + id: true, + type: true, + value: true, + // Add other fields as needed by callers + }, });
53-88: Add explicitselectto the Prisma query.This
findManyquery returns all fields from eachWatchlistrecord. Specify only the fields needed by callers.As per coding guidelines:
const blockedRecords = await db.watchlist.findMany({ where: { OR: [ ...(usernames.length > 0 ? [ { type: WatchlistType.USERNAME, value: { in: usernames, }, }, ] : []), ...(emails.length > 0 ? [ { type: WatchlistType.EMAIL, value: { in: emails, }, }, ] : []), ...(domains.length > 0 ? [ { type: WatchlistType.DOMAIN, value: { in: domains, }, }, ] : []), ], }, + select: { + id: true, + type: true, + value: true, + // Add other fields as needed by callers + }, });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/features/watchlist/watchlist.repository.ts(1 hunks)packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{service,repository}.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Avoid dot-suffixes like
.service.tsor.repository.tsfor new files; reserve.test.ts,.spec.ts,.types.tsfor their specific purposes
Files:
packages/features/watchlist/watchlist.repository.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/watchlist/watchlist.repository.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/features/watchlist/watchlist.repository.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/watchlist/watchlist.repository.ts
🔇 Additional comments (1)
packages/features/watchlist/watchlist.repository.ts (1)
4-4: LGTM! Import correctly updated.The removal of
WatchlistSeverityfrom imports aligns with the schema migration that drops this enum type.
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Show resolved
Hide resolved
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Show resolved
Hide resolved
packages/prisma/migrations/20251003103832_upsert_watchlist_audit/migration.sql
Outdated
Show resolved
Hide resolved
E2E results are ready! |
What does this PR do?
Updates the Watchlist Schema to include Reporting & Blocking feature changes, and an audit trail
Visual Demo (For contributors especially)
A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).
Video Demo (if applicable):
Image Demo (if applicable):
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist