Skip to content
Merged
Prev Previous commit
Next Next commit
fix: insert_ref_certificate returns persisted id via RETURNING; issue…
…_ref_certificate uses it
  • Loading branch information
Gravirei committed Jul 10, 2026
commit d63731602c06a20aac9b258c37c8597cee7fb892
5 changes: 3 additions & 2 deletions crates/gitlawb-node/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn issue_ref_certificate(

let signature = state.node_keypair.sign_b64(&payload_bytes);

let cert = RefCertificate {
let mut cert = RefCertificate {
id: Uuid::new_v4().to_string(),
repo_id: repo_id.to_string(),
ref_name: ref_name.to_string(),
Expand All @@ -52,6 +52,7 @@ pub async fn issue_ref_certificate(
issued_at,
};

state.db.insert_ref_certificate(&cert).await?;
let persisted_id = state.db.insert_ref_certificate(&cert).await?;
cert.id = persisted_id;
Ok(cert)
}
14 changes: 9 additions & 5 deletions crates/gitlawb-node/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,8 +1970,11 @@ impl Db {
// ── Ref Certificates ──────────────────────────────────────────────────────────

impl Db {
pub async fn insert_ref_certificate(&self, cert: &RefCertificate) -> Result<()> {
sqlx::query(
/// Insert a ref certificate, or update it if a row for `(repo_id, ref_name)`
/// already exists. Returns the id of the row that is now in the database
/// (the original id on upsert; the passed id on insert).
pub async fn insert_ref_certificate(&self, cert: &RefCertificate) -> Result<String> {
let row: (String,) = sqlx::query_as(
"INSERT INTO ref_certificates
(id, repo_id, ref_name, old_sha, new_sha, pusher_did, node_did, signature, issued_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
Expand All @@ -1981,7 +1984,8 @@ impl Db {
pusher_did = EXCLUDED.pusher_did,
node_did = EXCLUDED.node_did,
signature = EXCLUDED.signature,
issued_at = EXCLUDED.issued_at",
issued_at = EXCLUDED.issued_at
RETURNING id",
)
.bind(&cert.id)
.bind(&cert.repo_id)
Expand All @@ -1992,9 +1996,9 @@ impl Db {
.bind(&cert.node_did)
.bind(&cert.signature)
.bind(&cert.issued_at)
.execute(&self.pool)
.fetch_one(&self.pool)
.await?;
Ok(())
Ok(row.0)
}

pub async fn list_ref_certificates(
Expand Down