guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: Handle when there's no system-test-data to insert


From: Christopher Baines
Subject: 01/03: Handle when there's no system-test-data to insert
Date: Mon, 20 Apr 2020 03:21:04 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit fdee09d1c0c475451eb865276dbc694c3a1beba4
Author: Christopher Baines <address@hidden>
AuthorDate: Mon Apr 20 08:17:31 2020 +0100

    Handle when there's no system-test-data to insert
    
    Previously it would error in one of the INSERT queries.
---
 guix-data-service/model/system-test.scm | 83 +++++++++++++++++----------------
 1 file changed, 42 insertions(+), 41 deletions(-)

diff --git a/guix-data-service/model/system-test.scm 
b/guix-data-service/model/system-test.scm
index 090ba58..665eff2 100644
--- a/guix-data-service/model/system-test.scm
+++ b/guix-data-service/model/system-test.scm
@@ -30,51 +30,52 @@
 (define (insert-system-tests-for-guix-revision conn
                                                guix-revision-id
                                                system-test-data)
-  (let* ((system-test-ids
-          (insert-missing-data-and-return-all-ids
-           conn
-           "system_tests"
-           '(name description location_id)
-           (map (match-lambda
-                  ((name description derivation-file-names-by-system 
location-data)
-                   (list name
-                         description
-                         (location->location-id
-                          conn
-                          (apply location location-data)))))
-                system-test-data)))
-         (data
-          (append-map
-           (lambda (system-test-id derivation-file-names-by-system)
-             (let ((systems
-                    (map car derivation-file-names-by-system))
-                   (derivation-ids
-                    (derivation-file-names->derivation-ids
-                     conn
-                     (map cdr derivation-file-names-by-system))))
-               (map (lambda (system derivation-id)
-                      (list guix-revision-id
-                            system-test-id
-                            derivation-id
-                            system))
-                    systems
-                    derivation-ids)))
-           system-test-ids
-           (map third system-test-data))))
+  (unless (null? system-test-data)
+    (let* ((system-test-ids
+            (insert-missing-data-and-return-all-ids
+             conn
+             "system_tests"
+             '(name description location_id)
+             (map (match-lambda
+                    ((name description derivation-file-names-by-system 
location-data)
+                     (list name
+                           description
+                           (location->location-id
+                            conn
+                            (apply location location-data)))))
+                  system-test-data)))
+           (data
+            (append-map
+             (lambda (system-test-id derivation-file-names-by-system)
+               (let ((systems
+                      (map car derivation-file-names-by-system))
+                     (derivation-ids
+                      (derivation-file-names->derivation-ids
+                       conn
+                       (map cdr derivation-file-names-by-system))))
+                 (map (lambda (system derivation-id)
+                        (list guix-revision-id
+                              system-test-id
+                              derivation-id
+                              system))
+                      systems
+                      derivation-ids)))
+             system-test-ids
+             (map third system-test-data))))
 
-    (exec-query
-     conn
-     (string-append
-      "
+      (exec-query
+       conn
+       (string-append
+        "
 INSERT INTO guix_revision_system_test_derivations
   (guix_revision_id, system_test_id, derivation_id, system)
 VALUES "
-      (string-join
-       (map (lambda (vals)
-              (apply simple-format #f "(~A, ~A, ~A, '~A')"
-                     vals))
-            data)
-       ", "))))
+        (string-join
+         (map (lambda (vals)
+                (apply simple-format #f "(~A, ~A, ~A, '~A')"
+                       vals))
+              data)
+         ", ")))))
   #t)
 
 (define (select-system-tests-for-guix-revision conn



reply via email to

[Prev in Thread] Current Thread [Next in Thread]