Skip to content

Commit

Permalink
Merge pull request #2615 from get10101/fix/duplicate-funding-rates
Browse files Browse the repository at this point in the history
Add `unique_end_date` constraint to `funding_rates` table
  • Loading branch information
luckysori authored Jun 6, 2024
2 parents 4d13e73 + d0e6b43 commit ee321aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 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);
9 changes: 3 additions & 6 deletions coordinator/src/funding_fee/db/funding_rates.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::schema::funding_rates;
use anyhow::bail;
use anyhow::Result;
use diesel::prelude::*;
use rust_decimal::prelude::FromPrimitive;
Expand Down Expand Up @@ -37,14 +36,12 @@ pub fn insert_funding_rates(
.map(NewFundingRate::from)
.collect::<Vec<_>>();

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

if affected_rows == 0 {
bail!("Failed to insert funding rates");
}

Ok(())
}

Expand Down

0 comments on commit ee321aa

Please sign in to comment.