Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique_end_date constraint to funding_rates table #2615

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading