fix(V2): cascade stage project/unit child deletes#1564
Merged
Conversation
Prevent orphaned child records by staging DELETE rows for project/unit children before parent deletion. This keeps staged changes aligned with the datalayer commit pipeline and makes delete responses explicit via stagedChildDeletes counts.
Wrap child and parent delete staging in one transaction so partial staging cannot commit child deletes without the parent row.
Reduce fixed waits and redundant setup in the v2 live-api job, and run cascade delete coverage from the existing data-short orchestration instead of a separate test process.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bf336d4. Configure here.
Install required system packages and Chia tools in one step per job so apt metadata refresh runs once after repository sources are configured.
getDiffObject returned diff.change={} for DELETE actions, but the
staging findAll controller strips raw data from the response. The
cascade delete live test relied on row.data (which was removed) causing
JSON.parse(undefined). Include parsed staging data in diff.change for
DELETE (matching INSERT/UPDATE behavior) and update the test to read
from diff.change.
Move reconcileOrganization() before the transaction in the resync controller so its non-transactional DB writes complete before the registry_hash='0' reset, preventing a race where reconcile overwrites the reset value. Fix V1 unit integration tests that checked staging-empty immediately after commit+sync. The sync task inserts data before its afterCommit callback truncates staging, so merge the staging-empty check into the poll condition. Also clear committed staging records before the split call so assertNoPendingCommits passes, and increase maxAttempts for the serial-number ordering test to handle sync backlog from prior tests.
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
src/utils/v2-cascade-delete.jsto stage child DELETE rows for project and unit delete flows before parent delete stagingproject-v2andunit-v2destroy handlers to invoke cascade staging and returnstagedChildDeletesTest plan
fnm use && npm run test:v2tests/v2/live-api/cascade-delete.live.spec.jsagainst a live CADT+datalayer environmentNote
Medium Risk
Touches V2 deletion/staging logic and introduces transactional, mutex-guarded cascade delete staging, which could affect data-layer consistency if incorrect. CI workflow changes (dependency install, service readiness checks) may also impact test stability across jobs.
Overview
Adds cascade delete staging for V2
projectandunitdeletes by introducingsrc/utils/v2-cascade-delete.jsto pre-stageDELETErows for dependent child records (e.g.,verification→issuance→unit→unit_label, plus other project children).Updates the V2
destroyhandlers to run cascade staging inside asequelizeV2transaction guarded byprocessingSyncRegistriesTransactionMutexV2, and returnsstagedChildDeletesin the API response; also reorders org resync reconciliation to occur before opening its transaction.Expands coverage with new V2 integration tests and a new live API suite (
tests/v2/live-api/cascade-delete.live.spec.js) and wires it intodata-short.js; CI workflow is tightened by usingnpm ci, consolidating system/Chia installs, adding CADT health polling, and removing some verbose port diagnostics.Reviewed by Cursor Bugbot for commit ed3fcc5. Bugbot is set up for automated code reviews on this repo. Configure here.