Skip to content

fix(reconciler): index missing for token updates#175

Open
dhyaniarun1993 wants to merge 4 commits intomainfrom
arun/fix/token-balances-index
Open

fix(reconciler): index missing for token updates#175
dhyaniarun1993 wants to merge 4 commits intomainfrom
arun/fix/token-balances-index

Conversation

@dhyaniarun1993
Copy link
Copy Markdown
Member

Problem

Migration 10_create_user_token_balances.go only calls CreateSchema, which creates the table but no unique indexes. Three ON CONFLICT clauses in pg.go require unique constraints that don't exist in the DB

/Users/arundhyani/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.darwin-amd64/src/runtime/proc.go:283
2026-04-01T18:52:04.236+0530	DEBUG	reconciler/reconciler.go:253	Updated user balances from holdings	{"party_id": "native_interop_2::1220ca015ab07c6d832b50dca28486cecf1bdc856deb81735441e731c6d3858b3aaa", "demo_balance": "0", "prompt_balance": "0"}
2026-04-01T18:52:04.238+0530	WARN	reconciler/reconciler.go:234	Failed to update DEMO balance	{"party_id": "native_interop_1::1220d0feac28475ae1f58f872a3d69677e650abb3b7dd2eef03c796669fa9af92c85", "error": "set balance for party native_interop_1::1220d0feac28475ae1f58f872a3d69677e650abb3b7dd2eef03c796669fa9af92c85 token DEMO: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification (SQLSTATE=42P10)"}
github.com/chainsafe/canton-middleware/pkg/reconciler.(*Reconciler).ReconcileUserBalancesFromHoldings
	/Users/arundhyani/Stuff/Project/canton/canton-middleware/pkg/reconciler/reconciler.go:234
main.main
	/Users/arundhyani/Stuff/Project/canton/canton-middleware/scripts/testing/interop-demo.go:220
runtime.main

Solution

Add the indexes in migration

@dhyaniarun1993 dhyaniarun1993 self-assigned this Apr 1, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new database migration that adds unique indexes to the user_token_balances table to support upsert operations. The feedback suggests refactoring both the up and down migration logic to utilize the bun ORM's schema builder instead of raw SQL strings, which would improve maintainability and ensure consistency with idiomatic Go practices when using this library.

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.

1 participant