Skip to content

Add script to remove partner self-referrals from ProgramApplicationEvent#3966

Closed
devkiran wants to merge 2 commits into
mainfrom
fix-partner-self-referrals
Closed

Add script to remove partner self-referrals from ProgramApplicationEvent#3966
devkiran wants to merge 2 commits into
mainfrom
fix-partner-self-referrals

Conversation

@devkiran
Copy link
Copy Markdown
Collaborator

@devkiran devkiran commented Jun 1, 2026

Summary by CodeRabbit

  • Chores
    • Added an administrative data maintenance tool to identify and correct invalid self-referral records in program application data.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 1, 2026

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 1, 2026 6:36am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a one-time maintenance script to remove self-referral relationships from the ProgramApplicationEvent table. The script identifies records where partnerId equals referredByPartnerId, logs the findings, and bulk-updates those records to null out the referral reference.

Changes

Self-referral cleanup maintenance script

Layer / File(s) Summary
Self-referral cleanup script
apps/web/scripts/misc/remove-self-referrals.ts
Prisma-backed maintenance script that queries ProgramApplicationEvent records where partnerId matches referredByPartnerId, logs matching rows, and performs a bulk update to clear the referredByPartnerId field for identified records.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • dubinc/dub#3956: Implements complementary self-referral prevention by tracking and updating referral relationships at runtime, while this PR removes existing self-referral records via bulk cleanup.

Suggested reviewers

  • steven-tey

Poem

🐰 A script hops through the data with care,
Self-referrals hiding everywhere,
With a wave of Prisma's magic wand,
Bad connections are now gone,

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a script to remove partner self-referrals from ProgramApplicationEvent.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-partner-self-referrals

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/scripts/misc/remove-self-referrals.ts`:
- Line 41: The script calls main() without handling errors or disconnecting
Prisma; wrap the entrypoint so you call main().catch(err => {
processLogger/error or console.error(err); process.exitCode = 1; }).finally(()
=> prisma.$disconnect()) to ensure the Prisma pool is released and failures set
a non-zero exit code; use the existing main() function and the prisma instance
(prisma.$disconnect()) and set process.exitCode rather than immediate
process.exit to allow graceful teardown.
- Around line 12-16: Change the raw SQL to use Prisma's default unquoted
identifiers for the ProgramApplicationEvent fields (ensure the prisma.$queryRaw
call selects id, partnerId, referredByPartnerId, visitedAt without any
backtick/quoted identifiers) so it matches the MySQL schema and Prisma model,
and add failure handling for the script by appending a catch to the main
invocation—call main().catch(e => { console.error(e); process.exit(1); }) to
ensure errors are logged and the process exits; refer to prisma.$queryRaw,
ProgramApplicationEvent, programApplicationEvents and main() when making these
edits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22fb011f-888d-42f4-83c0-52611f4d84de

📥 Commits

Reviewing files that changed from the base of the PR and between 6af085f and 41ad287.

📒 Files selected for processing (1)
  • apps/web/scripts/misc/remove-self-referrals.ts

Comment thread apps/web/scripts/misc/remove-self-referrals.ts
Comment thread apps/web/scripts/misc/remove-self-referrals.ts
@steven-tey
Copy link
Copy Markdown
Collaborator

Ran the script, closing the PR now, thank you @devkiran!

@steven-tey steven-tey closed this Jun 1, 2026
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