aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-12-15 10:32:40 +0000
committerChristopher Baines <mail@cbaines.net>2019-12-15 10:32:40 +0000
commita59f3520468e4002d60d7e1858f617c824cddc1f (patch)
tree5807646f33ea8abfbcd206299eb1cd26565e40a5
parentb693d3e57dbf3fe0b533b5d23ad97fa8209d2d5f (diff)
downloaddata-service-a59f3520468e4002d60d7e1858f617c824cddc1f.tar
data-service-a59f3520468e4002d60d7e1858f617c824cddc1f.tar.gz
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.
-rw-r--r--guix-data-service/model/build.scm37
1 files 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