Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/migrations/apidb/11_add_user_token_balances_indexes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package apidb

import (
"context"
"log"

"github.com/uptrace/bun"
)

func init() {
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
log.Println("adding unique indexes to user_token_balances...")

// These unique indexes back the ON CONFLICT upserts in reconciler/store/pg.go.
// Because the identifier columns are nullable, PostgreSQL allows multiple NULL rows
// in a unique index (NULL != NULL), so rows without a given identifier do not conflict.
for _, ddl := range []string{
`CREATE UNIQUE INDEX IF NOT EXISTS idx_utb_fingerprint_token
ON user_token_balances (fingerprint, token_symbol)`,
`CREATE UNIQUE INDEX IF NOT EXISTS idx_utb_evm_address_token
ON user_token_balances (evm_address, token_symbol)`,
`CREATE UNIQUE INDEX IF NOT EXISTS idx_utb_canton_party_token
ON user_token_balances (canton_party_id, token_symbol)`,
} {
if _, err := db.ExecContext(ctx, ddl); err != nil {
return err
}
}
Comment thread
dhyaniarun1993 marked this conversation as resolved.
Outdated
return nil
}, func(ctx context.Context, db *bun.DB) error {
log.Println("dropping unique indexes from user_token_balances...")
for _, ddl := range []string{
`DROP INDEX IF EXISTS idx_utb_fingerprint_token`,
`DROP INDEX IF EXISTS idx_utb_evm_address_token`,
`DROP INDEX IF EXISTS idx_utb_canton_party_token`,
} {
if _, err := db.ExecContext(ctx, ddl); err != nil {
return err
}
}
Comment thread
dhyaniarun1993 marked this conversation as resolved.
Outdated
return nil
})
}
Loading