fix(V2): guard shared deletes against staged references#1575
Merged
Conversation
Add referential integrity guards for methodology, program, stakeholder, and label deletes so they block when links exist in committed tables or in staged INSERT/UPDATE rows, with explicit force-delete override support. Extend integration coverage for live and staged reference conflicts and update live API delete helpers/docs to reflect and exercise the guard flow.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f121d6a. Configure here.
Address bugbot findings: add `committed: false` to the staging query to prevent double-counting references after commit but before sync cleanup, and replace the local toSnakeCase with the existing export from v2-camel-to-snake.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
methodology,program,stakeholder,label) to block deletes when references exist in committed tables or stagedINSERT/UPDATErows?force=truewhile preserving current staging flow and clear 409 conflict payloadsTest plan
eval \"$(fnm env)\" && fnm use && npm run test:v21378 passing,1 pending,1 failingV2 Project API - Basic CRUD Tests -> should stage only project delete when there are no child recordsPre-push review
Note
Medium Risk
Changes DELETE behavior for shared entities by introducing new 409 conflict responses unless
?force=trueis provided, which could impact existing clients and workflows. Logic also inspects stagedINSERT/UPDATErows, so incorrect counts or missed edge cases could block or allow deletes unexpectedly.Overview
Adds referential-integrity guards to V2 DELETE endpoints for shared records (
methodology,program,stakeholder,label), blocking deletion with409 Conflictwhen referenced by committed data or uncommitted stagedINSERT/UPDATErows; supports bypass via?force=true.Introduces
src/utils/v2-reference-guards.jsto centralize reference counting and standardize the 409 response payload, updates docs with new 409/force examples, and extends integration + live API tests to cover referenced, staged-referenced, and forced-delete cases.Reviewed by Cursor Bugbot for commit 3b0f920. Bugbot is set up for automated code reviews on this repo. Configure here.