Skip to content

Commit b52e82d

Browse files
Update applyUnappliedTxnAdditions to overwrite txn upon unique constraint failure (#1345)
2 parents bf67ee9 + e2ff20a commit b52e82d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stores/wallet.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"go.sia.tech/renterd/wallet"
1111
"go.sia.tech/siad/modules"
1212
"gorm.io/gorm"
13+
"gorm.io/gorm/clause"
1314
)
1415

1516
type (
@@ -329,7 +330,11 @@ func applyUnappliedOutputRemovals(tx *gorm.DB, oid hash256) error {
329330
}
330331

331332
func applyUnappliedTxnAdditions(tx *gorm.DB, txn dbTransaction) error {
332-
return tx.Create(&txn).Error
333+
return tx.Clauses(clause.OnConflict{
334+
Columns: []clause.Column{{Name: "transaction_id"}},
335+
UpdateAll: true,
336+
}).
337+
Create(&txn).Error
333338
}
334339

335340
func applyUnappliedTxnRemovals(tx *gorm.DB, txnID hash256) error {

0 commit comments

Comments
 (0)