Skip to content

Commit

Permalink
set sequence id to current db size with increment on nextval (#666)
Browse files Browse the repository at this point in the history
* set sequence id to current db size with increment on nextval

* fix test
  • Loading branch information
eaypek-tfh authored Nov 7, 2024
1 parent f345489 commit cd2166d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deploy/stage/common-values-iris-mpc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: "ghcr.io/worldcoin/iris-mpc:v0.9.2"
image: "ghcr.io/worldcoin/iris-mpc:v0.9.3"

environment: stage
replicaCount: 1
Expand Down
17 changes: 13 additions & 4 deletions iris-mpc-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,19 @@ DO UPDATE SET right_code = EXCLUDED.right_code, right_mask = EXCLUDED.right_mask
id: usize,
executor: impl sqlx::Executor<'_, Database = Postgres>,
) -> Result<()> {
sqlx::query("SELECT setval(pg_get_serial_sequence('irises', 'id'), $1 + 1, false)")
.bind(id as i64)
.execute(executor)
.await?;
if id == 0 {
// If requested id is 0 (only used in tests), reset the sequence to 1 with
// advance_nextval set to false. This is because serial id starts from 1.
sqlx::query("SELECT setval(pg_get_serial_sequence('irises', 'id'), 1, false)")
.execute(executor)
.await?;
} else {
sqlx::query("SELECT setval(pg_get_serial_sequence('irises', 'id'), $1, true)")
.bind(id as i64)
.execute(executor)
.await?;
}

Ok(())
}

Expand Down

0 comments on commit cd2166d

Please sign in to comment.