-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat(policy): support "insert on conflict update" #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds policy-enforcement transforms in PolicyHandler to apply read and mutation filters (SELECT/INSERT/UPDATE/DELETE), consolidates override logic, and adds tests covering policy-gated delete and query-builder update (including on-conflict updates). Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1){packages,samples,tests}/**📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (1)packages/runtime/src/plugins/policy/policy-handler.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @ymc9's task —— View job Code Review: Insert on Conflict Update FeatureI'll review this PR that adds support for "insert on conflict update" functionality to the policy system. Todo List
Code Review AnalysisPolicy Handler Changes (policy-handler.ts)The main changes are in the ✅ Code Quality & Best Practices
🔍 Potential Issues
🛡️ Security ConsiderationsThe implementation correctly applies access control policies to conflict resolution updates, which is crucial for maintaining data security. Users cannot bypass update policies through conflict resolution. ⚡ Performance ConsiderationsThe policy filter is only built once per query and reused, which is efficient. No performance concerns identified. Test Coverage Analysisdelete.test.ts - New File
update.test.ts - Enhanced FileThe new "insert on conflict do update" tests (lines 997-1051) are comprehensive:
🔧 Test Quality Assessment
Summary & Recommendations✅ Strengths
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for "insert on conflict update" (upsert) operations to the policy system, extending policy enforcement to cover the update portion of upsert queries.
- Added policy filter application to the "on conflict do update" portion of insert queries
- Restructured the PolicyHandler class with better organization using region comments
- Added comprehensive test coverage for both query builder updates and insert-on-conflict-update scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/runtime/src/plugins/policy/policy-handler.ts | Enhanced transformInsertQuery to apply update policies to conflict resolution and reorganized methods with region comments |
| packages/runtime/test/policy/crud/update.test.ts | Added test cases for query builder updates and insert-on-conflict-update policy enforcement |
| packages/runtime/test/policy/crud/delete.test.ts | New test file covering delete policy enforcement for both standard and query builder operations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Claude finished @ymc9's task —— View job Code Review: Insert on Conflict Update FeatureI've reviewed this PR that adds support for "insert on conflict update" functionality to the policy system. Todo List
Code Review AnalysisPolicy Handler Changes (policy-handler.ts:164-206)The main changes are in the ✅ Code Quality & Best Practices
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (7)
packages/runtime/src/plugins/policy/policy-handler.ts (6)
194-206: Returning rewrite: alias-awareness and “returning all” edge cases.If callers use aliased updates/deletes or
returningAll(),processReadBackmay emit selections referencing an alias while your read-backFROMdoesn’t set one. Consider normalizing: collect concrete column names (no alias), or reuse the same alias in the read-back SELECT.
232-240: onlyReturningId may misclassify when selections contain aliases/expressions.Collector-based equality against raw
idFieldscan return false negatives/positives if selections alias ID columns or include expressions. Consider normalizing selections to underlying column names before the subset check.
242-254: Skip pre-create check when create is unconditionally allowed.For inserts with unconditional-allow policy,
enforcePreCreatePolicyis unnecessary overhead if we’re only gating read-back. CacheconstConditionfrom above and skip this path when it’strue.
265-273: Pre-create evaluation and defaults.Setting non-provided fields to
nullfor policy evaluation can diverge from actual DB defaults/computed columns and wrongly deny creates. Consider incorporating schema defaults (if available) when synthesizing the VALUES row for checks.
385-411: Read-back with aliased mutations.If an UPDATE/DELETE was built with a table alias, reusing
node.returning.selectionsagainst a plainFROM TableNode.create(table)can reference a missing alias. Mirror the alias or dequalify selections.
432-447: DELETE support limited to single FROM.Throwing on multi-table DELETEs (
USING) is fine for now; consider documenting this constraint or guarding earlier to improve error messaging.packages/runtime/test/policy/crud/delete.test.ts (1)
29-50: Nice query builder assertions. Consider adding a targeted deleteMany(where) case.A small extra: assert that
deleteMany({ where: { x: { gt: 0 } } })respects policy and matches affected row count.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/runtime/src/plugins/policy/policy-handler.ts(2 hunks)packages/runtime/test/policy/crud/delete.test.ts(1 hunks)packages/runtime/test/policy/crud/update.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place packages only under
packages/,samples/, ortests/
Files:
packages/runtime/test/policy/crud/delete.test.tspackages/runtime/test/policy/crud/update.test.tspackages/runtime/src/plugins/policy/policy-handler.ts
🧬 Code graph analysis (3)
packages/runtime/test/policy/crud/delete.test.ts (1)
packages/runtime/test/policy/utils.ts (1)
createPolicyTestClient(14-25)
packages/runtime/test/policy/crud/update.test.ts (1)
packages/runtime/test/policy/utils.ts (1)
createPolicyTestClient(14-25)
packages/runtime/src/plugins/policy/policy-handler.ts (2)
packages/runtime/src/plugins/policy/utils.ts (1)
conjunction(49-67)packages/runtime/src/client/query-utils.ts (1)
getIdFields(57-60)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: claude-review
- GitHub Check: build-test (20.x)
🔇 Additional comments (4)
packages/runtime/test/policy/crud/delete.test.ts (1)
5-27: Good coverage for top-level delete and deleteMany.Scenarios validate both deny and allow paths and resulting counts. Looks solid.
packages/runtime/test/policy/crud/update.test.ts (2)
957-996: Query builder simple update: assertions align with injected policy filter.Verifies both targeted and blanket updates under
x > 1. Looks good.
997-1051: Upsert do-update tests: great—covers with/without WHERE and non-updatable vs updatable rows.This effectively exercises the new policy injection for
ON CONFLICT DO UPDATE.If you adjust
policy-handlerper my onConflict transformation comment, please re-run these two tests to confirm counts unchanged.packages/runtime/src/plugins/policy/policy-handler.ts (1)
169-184: No change needed —updateWhereis correct.
Verified: Kysely's OnConflictNode definesupdateWherefor DO UPDATE ... WHERE, so the code's use ofonConflict.updateWhereis valid.
Summary by CodeRabbit
New Features
Tests
Refactor