Skip to content

feat: Optimize PG graph database wipes - BED-8787#99

Open
StephenHinck wants to merge 1 commit into
mainfrom
BED-8787
Open

feat: Optimize PG graph database wipes - BED-8787#99
StephenHinck wants to merge 1 commit into
mainfrom
BED-8787

Conversation

@StephenHinck

@StephenHinck StephenHinck commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

Implements the new WipeGraph function supported optionally on DAWGS drivers to execute rapid graph wiping if supported. Initially, this is supported on PostgreSQL drivers utilizing TRUNCATE on node/edge tables. Additionally, adds an integration test to ensure that MigrationData node is retained post-truncation.

This is a requirement for SpecterOps/BloodHound#2936, however merging may occur in any order as the implementation is optional on all graph drivers.

Resolves: BED-8787

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

  • New Features
    • Added a graph wipe operation for PostgreSQL-backed databases, allowing all nodes and edges to be cleared in one action.
    • Supports an optional retain step so selected data can be recreated within the same operation.
  • Bug Fixes
    • Graph wipes now run transactionally, so any error during retention rolls back the cleanup and preserves existing data.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds a WipeGraph method to the Postgres driver that truncates the node and edge tables inside a WriteTransaction, then optionally calls a caller-provided retain delegate in the same transaction. An integration test validates truncate-with-retain, rollback-on-error, and nil-delegate truncation scenarios.

Changes

WipeGraph driver method and integration tests

Layer / File(s) Summary
WipeGraph driver method
drivers/pg/driver.go
Adds (*Driver).WipeGraph that runs truncate table node, edge; inside WriteTransaction, closes the result, wraps errors with context, and conditionally executes the retain delegate.
Integration tests
integration/wipe_graph_test.go
Adds TestWipeGraph (Postgres-only) with two seeded graph partitions, covering retain delegate, rollback on delegate error, and nil delegate; includes countNodes and countEdges read-transaction helpers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Suggested reviewers

  • seanjSO
  • superlinkx

Poem

🐇 Hop, hop, the tables fall,
TRUNCATE sweeps them, one and all.
A delegate may keep one node,
Or roll it back down the road.
Clean graphs bloom where old rows slept — what a tidy abode!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the PostgreSQL graph wipe optimization and matches the main change.
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.
Description check ✅ Passed The PR description follows the template and includes the change summary, issue reference, type, testing, driver impact, and checklist.
✨ 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-8787

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

@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.

Only note is that making this function available in the PG driver does not immediately expose it to consumers of the top-level graph interfaces. There may be some additional noodling here required to make this more accessible to library users.

Truncate statement looks good to me 👍

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