Skip to content

Commit

Permalink
fix(coordinator): Add unique_end_date constraint to funding_rates
Browse files Browse the repository at this point in the history
We only need one funding rate entry per `end_date`.

Without this change we were getting a new duplicate entry per
maker restart.

We `DO NOTHING` on conflict to ensure that the actually new rows in
the batch will be inserted if we encounter any conflicts.
  • Loading branch information
luckysori committed Jun 6, 2024
1 parent 4d13e73 commit 23ac948
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE funding_rates
DROP CONSTRAINT IF EXISTS unique_end_date;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE funding_rates
ADD CONSTRAINT unique_end_date UNIQUE (end_date);
2 changes: 2 additions & 0 deletions coordinator/src/funding_fee/db/funding_rates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub fn insert_funding_rates(

let affected_rows = diesel::insert_into(funding_rates::table)
.values(funding_rates)
.on_conflict(funding_rates::end_date)
.do_nothing()
.execute(conn)?;

if affected_rows == 0 {
Expand Down

0 comments on commit 23ac948

Please sign in to comment.