Investigation: Partner deletion cascade error with Prisma + PlanetScale#3282
Investigation: Partner deletion cascade error with Prisma + PlanetScale#3282
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
|
|
|
@copilot based on our commits from the last 7 days, what could potentially be causing this error? PrismaClientKnownRequestError: 10 }, This could be a bug with the Prisma adapter + Planetscale when deleting cascaded rows |
Based on my analysis of the codebase, the error is caused by Prisma's cascade delete handling with PlanetScale's relationMode. Here are the likely sources from recent changes: Root Cause: Potential Issues in Recent Code:
Fix Required: The schema shows 30+ models with |
Investigation Summary
This PR contains an investigation into a
PrismaClientKnownRequestErrorthat started occurring around December 22nd when attempting to delete Partner records. The error indicates:Unknown column 'ProgramEnrollment.programId' in 'field list'.Root Cause Identified
The error is caused by Prisma's cascade delete handling with PlanetScale's
relationMode = "prisma"configuration:relationMode = "prisma"(required for PlanetScale compatibility)ProgramEnrollmentrecords but fails because it cannot properly referenceProgramEnrollment.programIdin the deletion contextProblematic Code Identified
Two files were recently added (commit 51f4865) that rely on automatic cascade deletes instead of manual cleanup:
apps/web/lib/api/partners/bulk-delete-partners.tspartner.deleteMany()directly whendeletePartners=trueProgramEnrollmentrecordsapps/web/app/(ee)/api/admin/delete-partner-account/route.tspartner.delete()directlyRecommended Fix
Both files need to manually delete
ProgramEnrollmentrecords (and potentially other relations from the 30+ models that referencepartnerId) BEFORE deleting the Partner record itself, since PlanetScale doesn't support database-level foreign key constraints.Analysis Details
partnerIdfields that have cascading relationshipsonDelete: CascaderelationsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.