branch: main
commit 8b0c86a7b78173f335258ed9f3a711dedd887dd3
Author: Ludovic Courtès <l...@gnu.org>
AuthorDate: Wed Sep 18 20:12:45 2024 +0200

    database: ‘db-add-build’ returns the build ID.
    
    Previously it would return either 1 (the number of rows inserted)
    or #f.
    
    * src/cuirass/database.scm (db-add-build): Really return the build ID.
---
 src/cuirass/database.scm | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 4cf45db..5c101a5 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -833,8 +833,9 @@ INSERT INTO Outputs (derivation, name, path) VALUES ("
 ON CONFLICT ON CONSTRAINT outputs_pkey DO NOTHING;")))
 
 (define (db-add-build build)
-  "Store BUILD in database the database only if one of its outputs is new.
-Return #f otherwise.  BUILD outputs are stored in the OUTPUTS table."
+  "Store BUILD in database the database only if one of its outputs is new, and
+return its ID; return #f otherwise.  BUILD outputs are stored in the OUTPUTS
+table."
   (match (with-db-connection db
            (exec-query/bind db "
 INSERT INTO Builds (derivation, evaluation, job_name, system, nix_name, log,
@@ -853,10 +854,11 @@ VALUES ("
                             (build-creation-time build) ", "
                             (build-start-time build) ", "
                             (build-completion-time build) ")
-ON CONFLICT ON CONSTRAINT builds_derivation_key DO NOTHING;"))
-    (0                             ;a build for this derivation already exists
+ON CONFLICT ON CONSTRAINT builds_derivation_key DO NOTHING
+RETURNING id;"))
+    (()                            ;a build for this derivation already exists
      #f)
-    ((? integer? id)
+    ((((= string->number id)))
      (for-each db-add-output (build-outputs build))
      id)))
 

Reply via email to