chore: upsert any custom-node-kinds entries that are missing from kind table BED-7922#2829
chore: upsert any custom-node-kinds entries that are missing from kind table BED-7922#2829AD7ZJ wants to merge 15 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR refactors the custom node kinds data model from using a ChangesCustom Node Kind kind_id Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…nt for removal of the kind_name column.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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
`@cmd/api/src/database/migration/migrations/20260526065858_upsert_kind_from_custom_node_kind.sql`:
- Around line 110-111: The Down migration currently drops
ensure_stubbed_custom_node_kind_for_ingest(TEXT, JSONB) which breaks rollback
paths that still call it; instead, restore/recreate the old kind_name-based
implementation of ensure_stubbed_custom_node_kind_for_ingest in the Down block
(mirror the previous behavior before this migration) rather than dropping it —
implement the function body that accepts (TEXT, JSONB) and uses the old
kind_name logic to look up or stub a kind, matching the signature
ensure_stubbed_custom_node_kind_for_ingest(TEXT, JSONB) so pre-rollback code can
continue to call it.
- Line 16: The migration file
20260526065858_upsert_kind_from_custom_node_kind.sql is missing the required
<version> token in its filename; rename it to follow the repository convention
<timestamp>_<version>_<name>.sql (e.g.,
20260526065858_v9_upsert_kind_from_custom_node_kind.sql or the appropriate next
version like v10) so the goose migration loader recognizes it, and keep the file
contents (including the "-- +goose Up" header) unchanged.
🪄 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: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 90ad1b39-1b5f-4d89-bb7f-b1e20c94d8a0
📒 Files selected for processing (12)
cmd/api/src/api/v2/customnode.gocmd/api/src/api/v2/kinds.gocmd/api/src/api/v2/kinds_test.gocmd/api/src/database/customnode.gocmd/api/src/database/customnode_integration_test.gocmd/api/src/database/graphschema.gocmd/api/src/database/migration/goose_migration_integration_test.gocmd/api/src/database/migration/migrations/20260526065858_upsert_kind_from_custom_node_kind.sqlcmd/api/src/database/mocks/db.gocmd/api/src/database/upsert_schema_extension.gocmd/api/src/database/upsert_schema_extension_integration_test.gocmd/api/src/model/customnode.go
| err := s.AuditableTransaction(ctx, auditEntry, func(tx *gorm.DB) error { | ||
| if err := tx.Raw(fmt.Sprintf("DELETE FROM %s WHERE kind_name = ? RETURNING id, config;", model.CustomNodeKind{}.TableName()), kindName). | ||
| Row().Scan(&customNodeKind.ID, &customNodeKind.Config); errors.Is(err, sql.ErrNoRows) { | ||
| if err := tx.Raw( |
There was a problem hiding this comment.
Since we are upserting custom node kinds to the kind table would it make sense to delete them from the kinds table here as well? We would need to check that the kind is not part of a current extension for that.
There was a problem hiding this comment.
I actually think the opposite is true and this endpoint / handler might need to be deprecated.....
There was a problem hiding this comment.
I marked the handler as deprecated and removed the DeleteCustomNode() logic.
| err := s.AuditableTransaction(ctx, auditEntry, func(tx *gorm.DB) error { | ||
| if err := tx.Raw(fmt.Sprintf("DELETE FROM %s WHERE kind_name = ? RETURNING id, config;", model.CustomNodeKind{}.TableName()), kindName). | ||
| Row().Scan(&customNodeKind.ID, &customNodeKind.Config); errors.Is(err, sql.ErrNoRows) { | ||
| if err := tx.Raw( |
There was a problem hiding this comment.
I actually think the opposite is true and this endpoint / handler might need to be deprecated.....
urangel
left a comment
There was a problem hiding this comment.
I am unclear whether deprecating this endpoint is a palatable direction to take so will let @mistahj67 follow up on that request. Assuming we do want to go that route, the changes look good to me!
Description
This scans through the custom_node_kinds table and upserts to the kind table any kinds that are missing. It also gets rid of the custom_node_kind name column and makes a new kind_id column FK'ed to the kind table.
Motivation and Context
Resolves https://specterops.atlassian.net/browse/BED-7922
How Has This Been Tested?
A migration integration test has been created.
Screenshots (optional):
Types of changes
Checklist:
Summary by CodeRabbit
Bug Fixes
Chores
kind_id, including cleanup of reservedTag_kinds.Tests
kindIdresponse field, including added migration coverage.