fix(db): preserve parent_id on SQLite upsert conflict#4
Merged
Conversation
The ON CONFLICT clause in Put, PutMulti, and transaction Put only updated the data column, dropping parent_id on upsert. This caused ancestor queries (used by billing balance) to return zero results because transactions stored without parent_id were invisible to the WHERE parent_id = '1' filter. Add parent_id = excluded.parent_id to all three ON CONFLICT clauses so parent_id is always persisted on both insert and update paths.
The seed command imported the deprecated plan model which has no orm.Register() call, causing a panic: "type plan.Plan not registered". Switch to the active models/plan package which registers itself via init().
3 tasks
hanzo-dev
pushed a commit
that referenced
this pull request
May 13, 2026
* fix(db): preserve parent_id on SQLite upsert conflict The ON CONFLICT clause in Put, PutMulti, and transaction Put only updated the data column, dropping parent_id on upsert. This caused ancestor queries (used by billing balance) to return zero results because transactions stored without parent_id were invisible to the WHERE parent_id = '1' filter. Add parent_id = excluded.parent_id to all three ON CONFLICT clauses so parent_id is always persisted on both insert and update paths. * fix(seed): use active plan model instead of deprecated one The seed command imported the deprecated plan model which has no orm.Register() call, causing a panic: "type plan.Plan not registered". Switch to the active models/plan package which registers itself via init().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parent_idcolumn during SQLite upsert operationsON CONFLICTclause inPut(),PutMulti(), andsqliteTransaction.Put()only updateddata, silently droppingparent_idon conflict — ancestor queries (WHERE parent_id = '1') then returned zero resultsRoot Cause
Commerce uses Google Cloud Datastore-style ancestor queries for billing. Transactions are children of a
synckeyroot (parent_id = '1'). When an entity was upserted (INSERT...ON CONFLICT DO UPDATE), the UPDATE clause only setdataandupdated_at, omittingparent_id. This meant any re-saved transaction lost its parent linkage and became invisible to balance queries.Fix
Add
parent_id = excluded.parent_idto all three ON CONFLICT clauses indb/sqlite.go.Test plan
GET /api/v1/billing/balancereturns correct amount