From 3d66a8296769318540467151c48174c7e03d9bb5 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Thu, 31 Jul 2025 10:58:38 +0200 Subject: [PATCH] Use BIGSERIAL for postgres keys Signed-off-by: Lee Smet --- heromodels/src/db/postgres.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/heromodels/src/db/postgres.rs b/heromodels/src/db/postgres.rs index 3b568b5..f1cfe2c 100644 --- a/heromodels/src/db/postgres.rs +++ b/heromodels/src/db/postgres.rs @@ -138,7 +138,7 @@ WHERE table_name = $1 tx.execute( &format!( - "CREATE TABLE {} (key SERIAL PRIMARY KEY, value JSONB NOT NULL);", + "CREATE TABLE {} (key BIGSERIAL PRIMARY KEY, value JSONB NOT NULL);", Self::collection_name::(), ), &[], @@ -191,7 +191,7 @@ where "SELECT (value) FROM {} WHERE key = $1;", Self::collection_name::() ), - &[&id], + &[&(id as i64)], ) .map_err(Error::from)? .into_iter() @@ -231,14 +231,12 @@ where eprintln!("insert done"); // Get the generated ID - let id = row.get::<_, i32>("key") as u32; + let id = row.get::<_, i64>("key") as u32; let mut value = row.get::<_, postgres::types::Json>("value").0; // .map_err(Error::from)?; value.base_data_mut().id = id; // NOTE: Update the value so the id is set correctly in the value itself - // let ser_val = serde_json::to_string(&value).map_err(Error::from)?; - let updated = con .execute( &format!( @@ -247,7 +245,7 @@ where ), &[ &postgres::types::Json(value.clone()), - &(value.get_id() as i32), + &(value.get_id() as i64), ], ) .map_err(Error::from)?; @@ -266,7 +264,7 @@ where ), &[ &postgres::types::Json(value.clone()), - &(value.get_id() as i32), + &(value.get_id() as i64), ], ) .map_err(Error::from)?; @@ -307,7 +305,7 @@ where "DELETE FROM {} WHERE key = $1;", Self::collection_name::() ), - &[&id], + &[&(id as i64)], ) .map_err(Error::from)?;