From a59f3520468e4002d60d7e1858f617c824cddc1f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 15 Dec 2019 10:32:40 +0000 Subject: Split out select-build-by-build-server-and-derivation-file-name Create select-build-id-by-build-server-and-derivation-file-name, which just returns the id, and then a variant that returns more fields for making a page for each build. --- guix-data-service/model/build.scm | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/guix-data-service/model/build.scm b/guix-data-service/model/build.scm index 299cacd..6670246 100644 --- a/guix-data-service/model/build.scm +++ b/guix-data-service/model/build.scm @@ -154,7 +154,38 @@ ORDER BY latest_build_status.timestamp DESC") conn build-server-id derivation-file-name) (define query " -SELECT id, build_server_id, derivation_file_name +SELECT build_servers.url, + JSON_AGG( + json_build_object( + 'timestamp', build_status.timestamp, + 'status', build_status.status + ) + ORDER BY build_status.timestamp + ) AS statuses +FROM builds +INNER JOIN build_servers + ON build_servers.id = builds.build_server_id +INNER JOIN build_status + ON builds.id = build_status.build_id +WHERE build_server_id = $1 AND + derivation_file_name = $2 +GROUP BY build_servers.url") + + (match (exec-query conn + query + (list (number->string build-server-id) + derivation-file-name)) + (((build-server-url statuses-json)) + (list build-server-url + (json-string->scm statuses-json))) + (() + #f))) + +(define (select-build-id-by-build-server-and-derivation-file-name + conn build-server-id derivation-file-name) + (define query + " +SELECT id FROM builds WHERE build_server_id = $1 AND derivation_file_name = $2") @@ -162,7 +193,7 @@ WHERE build_server_id = $1 AND derivation_file_name = $2") query (list (number->string build-server-id) derivation-file-name)) - ((id build_server_id derivation_file_name) + ((id) (string->number id)) (_ #f))) @@ -254,7 +285,7 @@ RETURNING (id)" build-server-id derivation-file-name) (let ((existing-build-id - (select-build-by-build-server-and-derivation-file-name + (select-build-id-by-build-server-and-derivation-file-name conn build-server-id derivation-file-name))) (if existing-build-id -- cgit v1.2.3