Skip to content

Commit

Permalink
feat: restrict decreasing block range updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lok52 committed Nov 5, 2024
1 parent 67cb560 commit 581f870
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,29 @@ where
Entity::insert_many(block_ranges)
.on_conflict(
OnConflict::column(Column::ChainId)
.update_columns([Column::MinBlockNumber, Column::MaxBlockNumber])
.value(Column::UpdatedAt, Expr::current_timestamp())
.values([
(Column::UpdatedAt, Expr::current_timestamp().into()),
(
Column::MinBlockNumber,
Expr::cust_with_exprs(
"LEAST($1, $2)",
[
Column::MinBlockNumber.into_expr().into(),
Expr::cust("EXCLUDED.min_block_number"),
],
),
),
(
Column::MaxBlockNumber,
Expr::cust_with_exprs(
"GREATEST($1, $2)",
[
Column::MaxBlockNumber.into_expr().into(),
Expr::cust("EXCLUDED.max_block_number"),
],
),
),
])
.to_owned(),
)
.exec(db)
Expand Down

0 comments on commit 581f870

Please sign in to comment.