diff options
author | Christopher Baines <mail@cbaines.net> | 2020-05-23 21:05:44 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-05-23 21:05:44 +0100 |
commit | f11421824dd22d4d5ad49ebc190e654ab62517ff (patch) | |
tree | aaf0a313a420283f6116e43946433ac2e4379e0f /guix-data-service | |
parent | 9c72fc23dc7350300be0f18538eb9691ef058d40 (diff) | |
download | data-service-f11421824dd22d4d5ad49ebc190e654ab62517ff.tar data-service-f11421824dd22d4d5ad49ebc190e654ab62517ff.tar.gz |
Add a helper procedure to delete data for deleted branches
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/data-deletion.scm | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/guix-data-service/data-deletion.scm b/guix-data-service/data-deletion.scm index 296e000..5d127c9 100644 --- a/guix-data-service/data-deletion.scm +++ b/guix-data-service/data-deletion.scm @@ -20,7 +20,8 @@ #:use-module (ice-9 match) #:use-module (squee) #:use-module (guix-data-service database) - #:export (delete-data-for-branch)) + #:export (delete-data-for-branch + delete-data-for-all-deleted-branches)) (define (delete-data-for-branch conn git-repository-id branch-name) (define commits @@ -179,6 +180,30 @@ SELECT DISTINCT name FROM git_branches WHERE git_repository_id = 1 AND name != 'master'")))))) +(define (delete-data-for-all-deleted-branches) + (with-postgresql-connection + "data-deletion" + (lambda (conn) + (for-each + (match-lambda + ((name git-repository-id) + (simple-format #t "deleting data for ~A (~A)\n" + name git-repository-id) + (delete-data-for-branch conn + (string->number git-repository-id) + name))) + (exec-query + conn + " +SELECT name, git_repository_id +FROM ( + SELECT DISTINCT ON (name, git_repository_id) + name, git_repository_id, commit + FROM git_branches + ORDER BY git_repository_id, name, datetime DESC +) AS git_branches_latest_revision +WHERE commit = ''"))))) + (define (delete-unreferenced-derivations) (define (maybe-delete-derivation conn id file-name) (match (map |