Repository navigation
chore(ent): enable sql/upsert feature flag - #1200
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
f9615e7 to
cbc78ef
Compare
75e0ad4 to
b8748eb
Compare
cbc78ef to
e9c62db
Compare
b8748eb to
15cfae6
Compare
e9c62db to
b49741f
Compare
15cfae6 to
fca78b0
Compare
b49741f to
b5e2e6c
Compare
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughAdds SQL upsert (ON CONFLICT) support across generated Ent create builders by enabling code generation with the sql/upsert feature, adding conflict option storage and OnConflict entry points, and providing Upsert helper types for single-row and bulk insert conflict resolution. ChangesSQL upsert support for entity builders
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
fca78b0 to
3ab6f68
Compare
b5e2e6c to
fc295e1
Compare
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 `@ent/pinnedclosure_create.go`:
- Around line 577-581: PinnedClosureUpsertBulk.ExecX currently calls
u.create.Exec(ctx) directly and therefore bypasses the validation logic in
PinnedClosureUpsertBulk.Exec (conflict option checks and per-builder OnConflict
misuse checks). Fix by delegating ExecX to the validated path: call u.Exec(ctx)
and panic on the returned error instead of calling u.create.Exec(ctx), ensuring
the existing OnConflict/conflict-options validation in
PinnedClosureUpsertBulk.Exec is executed.
- Around line 323-336: ExecX and ID are bypassing the upsert validation by
calling the underlying create builder directly; change ExecX to delegate to the
existing upsert-aware Exec(ctx) (panic on its error) and change ID to first
invoke u.Exec(ctx) to enforce the missing-options guard before calling the
underlying create save path (e.g., call u.create.Save(ctx) only after
u.Exec(ctx) succeeds) so the OnConflict option validation runs.
🪄 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: 993a098b-62f5-4916-b490-63ce8ab0d4aa
📒 Files selected for processing (10)
ent/chunk_create.goent/configentry_create.goent/generate.goent/narfile_create.goent/narfilechunk_create.goent/narinfo_create.goent/narinfonarfile_create.goent/narinforeference_create.goent/narinfosignature_create.goent/pinnedclosure_create.go
| func (u *PinnedClosureUpsertOne) ExecX(ctx context.Context) { | ||
| if err := u.create.Exec(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| // Exec executes the UPSERT query and returns the inserted/updated ID. | ||
| func (u *PinnedClosureUpsertOne) ID(ctx context.Context) (id int, err error) { | ||
| node, err := u.create.Save(ctx) | ||
| if err != nil { | ||
| return id, err | ||
| } | ||
| return node.ID, nil | ||
| } |
There was a problem hiding this comment.
ExecX and ID bypass the upsert option validation path.
Line 324 and Line 331 call the underlying create builder directly, so the missing-options guard in Exec is skipped. This can silently run a non-upsert insert flow when OnConflict() is called without options.
Proposed fix
func (u *PinnedClosureUpsertOne) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
+ if err := u.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *PinnedClosureUpsertOne) ID(ctx context.Context) (id int, err error) {
+ if len(u.create.conflict) == 0 {
+ return 0, errors.New("ent: missing options for PinnedClosureCreate.OnConflict")
+ }
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}🤖 Prompt for 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.
In `@ent/pinnedclosure_create.go` around lines 323 - 336, ExecX and ID are
bypassing the upsert validation by calling the underlying create builder
directly; change ExecX to delegate to the existing upsert-aware Exec(ctx) (panic
on its error) and change ID to first invoke u.Exec(ctx) to enforce the
missing-options guard before calling the underlying create save path (e.g., call
u.create.Save(ctx) only after u.Exec(ctx) succeeds) so the OnConflict option
validation runs.
| func (u *PinnedClosureUpsertBulk) ExecX(ctx context.Context) { | ||
| if err := u.create.Exec(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
| } |
There was a problem hiding this comment.
PinnedClosureUpsertBulk.ExecX skips bulk upsert validation.
Line 578 calls u.create.Exec(ctx) directly, bypassing the validation in PinnedClosureUpsertBulk.Exec (missing conflict options and per-builder OnConflict misuse checks).
Proposed fix
func (u *PinnedClosureUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
+ if err := u.Exec(ctx); err != nil {
panic(err)
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (u *PinnedClosureUpsertBulk) ExecX(ctx context.Context) { | |
| if err := u.create.Exec(ctx); err != nil { | |
| panic(err) | |
| } | |
| } | |
| func (u *PinnedClosureUpsertBulk) ExecX(ctx context.Context) { | |
| if err := u.Exec(ctx); err != nil { | |
| panic(err) | |
| } | |
| } |
🤖 Prompt for 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.
In `@ent/pinnedclosure_create.go` around lines 577 - 581,
PinnedClosureUpsertBulk.ExecX currently calls u.create.Exec(ctx) directly and
therefore bypasses the validation logic in PinnedClosureUpsertBulk.Exec
(conflict option checks and per-builder OnConflict misuse checks). Fix by
delegating ExecX to the validated path: call u.Exec(ctx) and panic on the
returned error instead of calling u.create.Exec(ctx), ensuring the existing
OnConflict/conflict-options validation in PinnedClosureUpsertBulk.Exec is
executed.
3ab6f68 to
9949687
Compare
fc295e1 to
96e4a3d
Compare
There was a problem hiding this comment.
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 `@ent/chunk_create.go`:
- Around line 471-474: The ExecX methods are bypassing the validation logic in
Exec by calling u.create.Exec(ctx) directly; update ChunkUpsertOne.ExecX (and
ChunkUpsertBulk.ExecX) to invoke the validated method (call u.Exec(ctx) and
panic on the returned error) so conflict-option checks and per-builder conflict
misuse checks run the same path as Exec, rather than calling u.create.Exec(ctx)
directly.
🪄 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: ffc4dd08-5bfb-44de-9a33-d4d4d570aa44
📒 Files selected for processing (10)
ent/chunk_create.goent/configentry_create.goent/generate.goent/narfile_create.goent/narfilechunk_create.goent/narinfo_create.goent/narinfonarfile_create.goent/narinforeference_create.goent/narinfosignature_create.goent/pinnedclosure_create.go
✅ Files skipped from review due to trivial changes (6)
- ent/generate.go
- ent/narinfo_create.go
- ent/narfilechunk_create.go
- ent/narfile_create.go
- ent/pinnedclosure_create.go
- ent/narinforeference_create.go
| func (u *ChunkUpsertOne) ExecX(ctx context.Context) { | ||
| if err := u.create.Exec(ctx); err != nil { | ||
| panic(err) | ||
| } |
There was a problem hiding this comment.
ExecX bypasses upsert validation in Exec
ChunkUpsertOne.ExecX and ChunkUpsertBulk.ExecX call u.create.Exec(ctx) directly, so they skip the guardrails in Exec (missing conflict options and per-builder conflict misuse). This makes ExecX behavior diverge from “ExecX is like Exec”.
Suggested fix
func (u *ChunkUpsertOne) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
+ if err := u.Exec(ctx); err != nil {
panic(err)
}
}
@@
func (u *ChunkUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
+ if err := u.Exec(ctx); err != nil {
panic(err)
}
}Also applies to: 767-770
🤖 Prompt for 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.
In `@ent/chunk_create.go` around lines 471 - 474, The ExecX methods are bypassing
the validation logic in Exec by calling u.create.Exec(ctx) directly; update
ChunkUpsertOne.ExecX (and ChunkUpsertBulk.ExecX) to invoke the validated method
(call u.Exec(ctx) and panic on the returned error) so conflict-option checks and
per-builder conflict misuse checks run the same path as Exec, rather than
calling u.create.Exec(ctx) directly.
9949687 to
8f24530
Compare
96e4a3d to
ab5cee7
Compare
8f24530 to
8d9fd40
Compare
ab5cee7 to
0604b80
Compare
8d9fd40 to
ac82cc7
Compare
0604b80 to
a326646
Compare
§11.3 requires expressing PutNarInfo's UPSERT semantics (`INSERT ... ON CONFLICT (hash) DO UPDATE ... WHERE url IS NULL`) in Ent's fluent API. The OnConflict / UpsertOne / UpsertBulk builders are only emitted when the `sql/upsert` feature flag is on, so this commit turns it on and regenerates. What changed: - `ent/generate.go`: add `--feature sql/upsert` to the codegen invocation. Subsequent `go generate ./ent` invocations now always produce OnConflict-capable builders; CI's `git diff --exit-code ./ent/` check stays meaningful because the regenerated tree is committed here. - Every `<entity>_create.go` file gains an OnConflict method, a Conflict type that exposes per-field Update/UpdateNewValues/Ignore handlers, and the corresponding Upsert / UpsertOne / UpsertBulk types. Pure additions; no existing API changes. No call-site code uses OnConflict yet — §11.3's caller migrations land in the next commit. Adding the feature flag in its own commit keeps the §11.3 conversion diff focused on the behavioural change, not the ~4k lines of mechanical codegen. `go build ./...` succeeds, `golangci-lint run ./...` returns zero issues, no other commit in the stack is affected.
a326646 to
088f9bb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1200 +/- ##
=====================================
Coverage 5.68% 5.68%
=====================================
Files 6 6
Lines 387 387
=====================================
Hits 22 22
Misses 361 361
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
§11.3 requires expressing PutNarInfo's UPSERT semantics
(
INSERT ... ON CONFLICT (hash) DO UPDATE ... WHERE url IS NULL)in Ent's fluent API. The OnConflict / UpsertOne / UpsertBulk
builders are only emitted when the
sql/upsertfeature flagis on, so this commit turns it on and regenerates.
What changed:
ent/generate.go: add--feature sql/upsertto the codegeninvocation. Subsequent
go generate ./entinvocations nowalways produce OnConflict-capable builders; CI's
git diff --exit-code ./ent/check stays meaningful becausethe regenerated tree is committed here.
<entity>_create.gofile gains an OnConflict method,a Conflict type that exposes per-field
Update/UpdateNewValues/Ignore handlers, and the corresponding
Upsert / UpsertOne / UpsertBulk types. Pure additions; no
existing API changes.
No call-site code uses OnConflict yet — §11.3's caller
migrations land in the next commit. Adding the feature flag in
its own commit keeps the §11.3 conversion diff focused on the
behavioural change, not the ~4k lines of mechanical codegen.
go build ./...succeeds,golangci-lint run ./...returnszero issues, no other commit in the stack is affected.