diff options
Diffstat (limited to 'guix-data-service/model/git-repository.scm')
-rw-r--r-- | guix-data-service/model/git-repository.scm | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/guix-data-service/model/git-repository.scm b/guix-data-service/model/git-repository.scm index 5c605f8..b5f9fbe 100644 --- a/guix-data-service/model/git-repository.scm +++ b/guix-data-service/model/git-repository.scm @@ -20,9 +20,11 @@ #:use-module (ice-9 match) #:use-module (json) #:use-module (squee) + #:use-module (guix-data-service database) #:use-module (guix-data-service model utils) #:export (all-git-repositories select-git-repository + specify-git-repositories git-repository-query-substitutes? git-repository-id->url select-includes-and-excluded-branches-for-git-repository @@ -68,6 +70,46 @@ WHERE id = $1" (string=? fetch_with_authentication "t") (and=> poll-interval string->number))))) +(define (specify-git-repositories repositories) + (with-postgresql-connection + "specify-git-repositories" + (lambda (conn) + (with-postgresql-transaction + conn + (lambda (conn) + (let* ((existing-ids + (map first (all-git-repositories conn))) + (target-ids + (map (lambda (repo) + (or (assq-ref repo 'id) + (error "repository missing id"))) + repositories)) + (repositories-to-delete + (lset-difference equal? + existing-ids + target-ids))) + (for-each + (lambda (id-to-remove) + (simple-format (current-error-port) + "deleting repository ~A\n" + id-to-remove) + (exec-query + conn + "DELETE FROM git_repositories WHERE id = $1" + (list (number->string id-to-remove)))) + repositories-to-delete) + + (for-each + (lambda (repo) + (let ((fields (map car repo)) + (field-vals (map cdr repo))) + (update-or-insert + conn + "git_repositories" + fields + field-vals))) + repositories))))))) + (define (git-repository-query-substitutes? conn id) (match (exec-query conn @@ -97,7 +139,7 @@ WHERE id = $1" item)) lst)) - (match (exec-query + (match (exec-query-with-null-handling conn " SELECT included_branches, excluded_branches @@ -105,13 +147,11 @@ FROM git_repositories WHERE id = $1" (list (number->string id))) (((included_branches excluded_branches)) (values - (if (or (eq? #f included_branches) - (string-null? included_branches)) - '() + (if (NULL? included_branches) + included_branches (make-regexes (parse-postgresql-array-string included_branches))) - (if (or (eq? excluded_branches #f) - (string-null? excluded_branches)) + (if (NULL? excluded_branches) '() (make-regexes (parse-postgresql-array-string excluded_branches))))))) |