Skip to content

Add cascade delete on ProgramApplicationEvent enrollment relation#3917

Open
devkiran wants to merge 1 commit into
mainfrom
fix-e2e-cleanup
Open

Add cascade delete on ProgramApplicationEvent enrollment relation#3917
devkiran wants to merge 1 commit into
mainfrom
fix-e2e-cleanup

Conversation

@devkiran
Copy link
Copy Markdown
Collaborator

@devkiran devkiran commented May 18, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced database consistency for program application records during program enrollment updates.

Review Change Stack

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 18, 2026

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview May 18, 2026 7:41am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

The PR modifies the Prisma schema to add cascade-on-delete behavior to the programEnrollment relation in the ProgramApplicationEvent model. When a ProgramEnrollment is deleted, related ProgramApplicationEvent records will now automatically cascade-delete instead of following Prisma's default constraint behavior.

Changes

Database Schema Cascade Delete

Layer / File(s) Summary
ProgramApplicationEvent to ProgramEnrollment cascade delete
packages/prisma/schema/application.prisma
The programEnrollment relation field adds onDelete: Cascade, so deleting a ProgramEnrollment cascades deletion to its associated ProgramApplicationEvent records.

Possibly Related PRs

  • dubinc/dub#3857: Applies similar onDelete: Cascade pattern to the DiscoveredPartner model's programEnrollment relation, suggesting a broader consistency alignment across enrollment-related models.

Suggested Reviewers

  • steven-tey

Poem

🐰 A cascade so clean, a delete so true,
When enrollments depart, events vanish too,
No orphans remain in the data we keep,
Just tidy relations running deep!

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 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 pull request title accurately and clearly summarizes the main change: adding cascade delete behavior to the programEnrollment relation in ProgramApplicationEvent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-e2e-cleanup

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: 1

🤖 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 `@packages/prisma/schema/application.prisma`:
- Line 61: The relation ProgramApplicationEvent -> programEnrollment currently
has onDelete: Cascade which will remove all ProgramApplicationEvent rows when a
ProgramEnrollment is deleted; to prevent loss of analytics, remove or change the
cascade to a safer behavior (e.g., onDelete: Restrict or onDelete: SetNull) on
the programEnrollment relation in application.prisma (affecting the
ProgramApplicationEvent model and the ProgramEnrollment relation), and if
cascade was intended only for tests, instead implement explicit test teardown or
a test-only schema; after changing the relation, generate and review the
corresponding migration so it reflects the non-destructive delete policy for
production.
🪄 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: 47652a4f-3848-4837-8b25-91337f041ab1

📥 Commits

Reviewing files that changed from the base of the PR and between c4706da and 502d585.

📒 Files selected for processing (1)
  • packages/prisma/schema/application.prisma

referredByPartner Partner? @relation(fields: [referredByPartnerId], references: [id])
application ProgramApplication? @relation(fields: [programApplicationId], references: [id])
programEnrollment ProgramEnrollment? @relation(fields: [programId, partnerId], references: [programId, partnerId])
programEnrollment ProgramEnrollment? @relation(fields: [programId, partnerId], references: [programId, partnerId], onDelete: Cascade)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for recent migration files related to this change
fd -e sql -t f . packages/prisma/migrations --exec ls -lt {} \; | head -20

Repository: dubinc/dub

Length of output: 168


🏁 Script executed:

#!/bin/bash  
# Check if ProgramApplicationEvent data is used for analytics/reporting
rg -n -C3 "ProgramApplicationEvent" --type=ts -g '!*.prisma' -g '!*test*' | head -50

Repository: dubinc/dub

Length of output: 3669


🏁 Script executed:

# Verify the actual content of line 61 in the schema file
sed -n '55,65p' packages/prisma/schema/application.prisma

Repository: dubinc/dub

Length of output: 558


🏁 Script executed:

# Find the correct location of migration files
find . -type d -name migrations | head -10

Repository: dubinc/dub

Length of output: 84


🏁 Script executed:

# Check for migration files related to ProgramEnrollment or ProgramApplication
find . -name '*migration*' -type f | grep -i prisma | head -20

Repository: dubinc/dub

Length of output: 36


🏁 Script executed:

# Verify the exact state of the programEnrollment relation
rg -A2 -B2 'programEnrollment.*`@relation`' packages/prisma/schema/

Repository: dubinc/dub

Length of output: 7223


Verify that cascading deletion of event data is intentional and scoped appropriately.

Adding onDelete: Cascade to the programEnrollment relation will automatically delete all related ProgramApplicationEvent records when a ProgramEnrollment is deleted. This is problematic because ProgramApplicationEvent is actively used for production analytics and reporting (tracked in apps/web/app/(ee)/api/partners/applications/analytics/route.ts for submissions, approvals, and rejections metrics).

A few considerations:

  1. Analytics impact: Deleting these events will affect historical reporting and analytics that depend on ProgramApplicationEvent data.

  2. Codebase consistency: This pattern (onDelete: Cascade on programEnrollment relations) is used elsewhere in the codebase (tag.prisma, network.prisma, fraud.prisma, bounty.prisma), suggesting it may be an accepted pattern. However, each should be evaluated based on the criticality of the data involved.

  3. Scope verification: Confirm whether this cascade behavior is intended for test cleanup only (e2e-cleanup PR context) or applies to production. If test-only, consider a separate schema or explicit test teardown logic.

Verify that the corresponding migration file aligns with these data retention requirements and that production analytics will not be affected.

🤖 Prompt for 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.

In `@packages/prisma/schema/application.prisma` at line 61, The relation
ProgramApplicationEvent -> programEnrollment currently has onDelete: Cascade
which will remove all ProgramApplicationEvent rows when a ProgramEnrollment is
deleted; to prevent loss of analytics, remove or change the cascade to a safer
behavior (e.g., onDelete: Restrict or onDelete: SetNull) on the
programEnrollment relation in application.prisma (affecting the
ProgramApplicationEvent model and the ProgramEnrollment relation), and if
cascade was intended only for tests, instead implement explicit test teardown or
a test-only schema; after changing the relation, generate and review the
corresponding migration so it reflects the non-destructive delete policy for
production.

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.

1 participant