Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Dec 5, 2025

CleanShot 2025-12-05 at 13 25 02

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue preventing deletion of the poly.market domain.
  • Improvements

    • Added safeguard to prevent deletion of domains actively used in partner programs, returning an informative error message.
    • Enhanced deletion tracking and record management for better audit trails.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Contributor

vercel bot commented Dec 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Dec 5, 2025 9:33pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

This PR enforces a deletion guard for domains active in partner programs by establishing a Domain-Program relation in Prisma, extending the domain retrieval to include partnerProgram data, and adding a 403 check in the DELETE route. Additionally, a temporary skip on poly.market domain deletion is removed, and the cron deletion recording is updated with a deleted flag.

Changes

Cohort / File(s) Summary
Domain Deletion Guards
apps/web/app/api/domains/[domain]/route.ts
Added partnerProgram check in DELETE handler; returns 403 if domain is active in a partner program
Cron Domain Deletion
apps/web/app/(ee)/api/cron/domains/delete/route.ts
Removed poly.market deletion skip; updated Tinybird recordLink call with deleted: true flag
Domain Data Retrieval
apps/web/lib/api/domains/get-domain-or-throw.ts
Extended Prisma include to eager-load partnerProgram relation
Prisma Schema
packages/prisma/schema/domain.prisma, packages/prisma/schema/program.prisma
Added optional partnerProgram relation to Domain model; made Program.domain unique and established customDomain relation from Program

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Schema migration: Verify unique constraint on Program.domain doesn't conflict with existing data and check one-to-one relation cardinality
  • Deletion guard logic: Confirm partnerProgram boolean flag accurately reflects whether a domain is actively used in a partner program
  • Cron job changes: Validate impact of removing poly.market skip and deleted: true flag on Tinybird record tracking

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

🐰 Hop skip through the partner domains so fine,
With relations now locked, they're safely mine,
A guard at the gate says "thou shalt not delete,"
When programs are bound, the dance stays complete!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Prevent deleting program domains' accurately captures the main objective of the pull request, which adds validation to prevent deletion of domains that are active in partner programs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-domain-delete

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28085e4 and 822f507.

📒 Files selected for processing (5)
  • apps/web/app/(ee)/api/cron/domains/delete/route.ts (1 hunks)
  • apps/web/app/api/domains/[domain]/route.ts (2 hunks)
  • apps/web/lib/api/domains/get-domain-or-throw.ts (1 hunks)
  • packages/prisma/schema/domain.prisma (1 hunks)
  • packages/prisma/schema/program.prisma (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: steven-tey
Repo: dubinc/dub PR: 2951
File: apps/web/scripts/migrations/backfill-submission-completedat.ts:16-24
Timestamp: 2025-10-09T19:50:25.662Z
Learning: Skip reviewing changes in the `scripts/` directory for the dubinc/dub repository.
📚 Learning: 2025-10-28T19:17:28.085Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2985
File: apps/web/app/(ee)/api/network/programs/[programSlug]/route.ts:20-27
Timestamp: 2025-10-28T19:17:28.085Z
Learning: In this codebase, Prisma's extendedWhereUnique feature is enabled (or Prisma 5.x is used), allowing findUniqueOrThrow to accept additional non-unique filters alongside unique fields like slug. This pattern is valid and acceptable.

Applied to files:

  • apps/web/lib/api/domains/get-domain-or-throw.ts
📚 Learning: 2025-06-06T07:59:03.120Z
Learnt from: devkiran
Repo: dubinc/dub PR: 2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.

Applied to files:

  • apps/web/app/(ee)/api/cron/domains/delete/route.ts
🧬 Code graph analysis (2)
apps/web/app/api/domains/[domain]/route.ts (2)
apps/web/lib/api/domains/get-domain-or-throw.ts (1)
  • getDomainOrThrow (7-53)
apps/web/lib/api/errors.ts (1)
  • DubApiError (58-75)
apps/web/app/(ee)/api/cron/domains/delete/route.ts (1)
apps/web/lib/tinybird/record-link.ts (1)
  • recordLink (75-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
apps/web/lib/api/domains/get-domain-or-throw.ts (1)

18-21: LGTM!

The addition of partnerProgram: true to the include clause correctly extends the domain query to fetch the associated program relation, enabling the deletion guard in the DELETE route.

packages/prisma/schema/domain.prisma (1)

24-24: LGTM!

The optional partnerProgram relation correctly establishes the back-reference from Domain to Program, enabling the deletion guard to check if a domain is associated with a partner program.

apps/web/app/(ee)/api/cron/domains/delete/route.ts (1)

62-63: LGTM!

Correctly passing { deleted: true } to recordLink ensures link deletions are properly tracked in Tinybird for analytics purposes.

packages/prisma/schema/program.prisma (1)

34-35: LGTM!

The @unique constraint on domain and the customDomain relation correctly establish a one-to-one relationship between Program and Domain. The absence of onDelete cascade ensures database-level protection as a fallback, complementing the application-level guard in the DELETE route.

Also applies to: 55-55

apps/web/app/api/domains/[domain]/route.ts (1)

226-249: LGTM!

The deletion guard correctly prevents deletion of domains that are actively used in partner programs. The check is properly placed after the registered domain check and before any deletion logic, with a clear error message for the user.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steven-tey steven-tey merged commit ed22fda into main Dec 5, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the fix-domain-delete branch December 5, 2025 21:57
@mustafa-poly
Copy link

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants