Skip to content

feat: Update deletion trigger to run on statement - BED-8796#100

Merged
StephenHinck merged 3 commits into
mainfrom
BED-8796
Jun 30, 2026
Merged

feat: Update deletion trigger to run on statement - BED-8796#100
StephenHinck merged 3 commits into
mainfrom
BED-8796

Conversation

@StephenHinck

@StephenHinck StephenHinck commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

BloodHound primarily works with PG in batch data, it is rare for the application to delete a single node or edge. By moving the table trigger to delete edges associated with nodes to FOR EACH STATEMENT, batch node deletes will call a single edge deletion, rather than running for every deleted node, improving DB performance across all deletions.

Resolves: BED-8796

Type of Change

  • Chore (a change that does not modify the application functionality)
  • Bug fix (a change that fixes an issue)
  • New feature / enhancement (a change that adds new functionality)
  • Refactor (no behaviour change)
  • Test coverage
  • Build / CI / tooling
  • Documentation

Testing

  • Unit tests added / updated
  • Integration tests added / updated
  • Full test suite run (make test_all with CONNECTION_STRING set)

Screenshots (if appropriate):

Driver Impact

  • PostgreSQL driver (drivers/pg)
  • Neo4j driver (drivers/neo4j)

Checklist

  • Code is formatted
  • All existing tests pass
  • go.mod / go.sum are up to date if dependencies changed

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved PostgreSQL cascade deletes when deleting multiple nodes in a single operation, ensuring incident edges are removed accurately.
  • Tests

    • Added an integration test that batch-deletes nodes in one statement and verifies remaining nodes and remaining edge rows.
  • Chores

    • Updated Go module dependencies to newer versions for ongoing compatibility and reliability.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70235971-61da-4409-900c-9f6fe37aa97f

📥 Commits

Reviewing files that changed from the base of the PR and between f0239e1 and 33c57ef.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (1)
  • integration/pgsql_delete_cascade_test.go

Walkthrough

PostgreSQL delete cascading now uses a statement-level trigger with a transition table for deleted node ids. A new manual integration test verifies batch node deletion and remaining node/edge counts. Go module versions are also updated.

Changes

Statement-level cascade delete trigger

Layer / File(s) Summary
Trigger rework to statement-level
drivers/pg/query/sql/schema_up.sql
delete_node_edges() and its trigger definition now use REFERENCING OLD TABLE AS deleted_nodes with FOR EACH STATEMENT; edge deletion matches ids from that deleted-node set instead of OLD.id per row.
Integration test for cascade behavior
integration/pgsql_delete_cascade_test.go
New manual_integration-tagged test builds a small node-and-edge fixture, deletes multiple nodes in one statement, and checks surviving nodes with Cypher and surviving edges with raw SQL helpers.

Go dependency updates

Layer / File(s) Summary
Dependency version bumps
go.mod
go.mod pins newer versions of golang.org/x/term, golang.org/x/crypto, golang.org/x/sys, golang.org/x/text, mattn/go-runewidth, pkg/errors, stretchr/objx, and adds clipperhouse/uax29/v2.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • brandonshearin
  • urangel

Poem

🐇 I hop through rows, then hop through sets,
One trigger swish, no row-by-row regrets.
The test says counts, the SQL sings bright,
Edges stay or vanish in the same SQL night.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: switching the deletion trigger to statement-level execution.
Description check ✅ Passed The description covers the change, ticket, change type, testing, driver impact, and checklist, matching the template well.
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.
✨ 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 BED-8796

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@integration/pgsql_delete_cascade_test.go`:
- Around line 105-107: The cascade-delete assertion is currently querying via
countByCypher on CascadeDeleteNode/CascadeDeleteEdge, which only sees
relationships whose endpoints still exist. Update the pgsql_delete_cascade_test
check to count the edge table directly with a SQL count(*) against the edge
storage so orphaned CascadeDeleteEdge rows are detected; keep the existing
expectation and adjust the helper usage in this test block accordingly.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 71bb1960-c899-4331-b423-44347be4b163

📥 Commits

Reviewing files that changed from the base of the PR and between 8fbfba4 and f0239e1.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • drivers/pg/query/sql/schema_up.sql
  • go.mod
  • integration/pgsql_delete_cascade_test.go

Comment thread integration/pgsql_delete_cascade_test.go Outdated

@zinic zinic left a comment

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.

This looks completely reasonable to me. No nits from my side.

@StephenHinck StephenHinck merged commit 44b68ea into main Jun 30, 2026
9 checks passed
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.

2 participants