Further data deletion improvements
This commit is contained in:
parent
65e8bf3f8d
commit
52a23a5333
1 changed files with 38 additions and 11 deletions
|
|
@ -23,7 +23,9 @@
|
||||||
#:use-module (guix-data-service model package-derivation-by-guix-revision-range)
|
#:use-module (guix-data-service model package-derivation-by-guix-revision-range)
|
||||||
#:export (delete-data-for-branch
|
#:export (delete-data-for-branch
|
||||||
delete-revisions-from-branch-except-most-recent-n
|
delete-revisions-from-branch-except-most-recent-n
|
||||||
delete-data-for-all-deleted-branches))
|
delete-revisions-for-all-branches-except-most-recent-n
|
||||||
|
delete-data-for-all-deleted-branches
|
||||||
|
delete-unreferenced-derivations))
|
||||||
|
|
||||||
(define (delete-revisions-from-branch conn git-repository-id branch-name commits)
|
(define (delete-revisions-from-branch conn git-repository-id branch-name commits)
|
||||||
(define (delete-jobs conn)
|
(define (delete-jobs conn)
|
||||||
|
|
@ -111,15 +113,16 @@ WHERE guix_revisions.git_repository_id = "
|
||||||
FROM git_branches
|
FROM git_branches
|
||||||
)")))))
|
)")))))
|
||||||
|
|
||||||
(unless (null? guix-revision-ids)
|
(exec-query
|
||||||
(for-each (lambda (guix-revision-id)
|
conn
|
||||||
(delete-guix-revision-package-derivation-entries
|
"
|
||||||
conn
|
DELETE FROM package_derivations_by_guix_revision_range
|
||||||
(number->string git-repository-id)
|
WHERE git_repository_id = $1 AND
|
||||||
guix-revision-id
|
branch_name = $2"
|
||||||
branch-name))
|
(list (number->string git-repository-id)
|
||||||
guix-revision-ids)
|
branch-name))
|
||||||
|
|
||||||
|
(unless (null? guix-revision-ids)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (table)
|
(lambda (table)
|
||||||
(exec-query
|
(exec-query
|
||||||
|
|
@ -152,7 +155,13 @@ DELETE FROM ~A WHERE ~A IN (VALUES ~A)"
|
||||||
DELETE FROM guix_revisions
|
DELETE FROM guix_revisions
|
||||||
WHERE id IN ("
|
WHERE id IN ("
|
||||||
(string-join guix-revision-ids ", ")
|
(string-join guix-revision-ids ", ")
|
||||||
")")))))))
|
")
|
||||||
|
AND id NOT IN (
|
||||||
|
SELECT id FROM guix_revisions
|
||||||
|
INNER JOIN git_branches ON
|
||||||
|
git_branches.commit = guix_revisions.commit AND
|
||||||
|
git_branches.git_repository_id = guix_revisions.git_repository_id
|
||||||
|
)")))))))
|
||||||
|
|
||||||
(define (delete-data-for-branch conn git-repository-id branch-name)
|
(define (delete-data-for-branch conn git-repository-id branch-name)
|
||||||
(define commits
|
(define commits
|
||||||
|
|
@ -188,7 +197,7 @@ OFFSET $3"
|
||||||
(number->string n)))))
|
(number->string n)))))
|
||||||
|
|
||||||
(unless (null? commits)
|
(unless (null? commits)
|
||||||
(simple-format #t "deleting ~A commits\n" (length commits))
|
(simple-format #t "deleting ~A commits from ~A\n" (length commits) branch-name)
|
||||||
(delete-revisions-from-branch conn
|
(delete-revisions-from-branch conn
|
||||||
git-repository-id
|
git-repository-id
|
||||||
branch-name
|
branch-name
|
||||||
|
|
@ -200,6 +209,24 @@ OFFSET $3"
|
||||||
git-repository-id)
|
git-repository-id)
|
||||||
branch-name)))
|
branch-name)))
|
||||||
|
|
||||||
|
(define (delete-revisions-for-all-branches-except-most-recent-n n)
|
||||||
|
(with-postgresql-connection
|
||||||
|
"data-deletion"
|
||||||
|
(lambda (conn)
|
||||||
|
(for-each
|
||||||
|
(match-lambda
|
||||||
|
((git-repository-id branch-name)
|
||||||
|
(delete-revisions-from-branch-except-most-recent-n
|
||||||
|
conn
|
||||||
|
(string->number git-repository-id)
|
||||||
|
branch-name
|
||||||
|
n)))
|
||||||
|
(exec-query
|
||||||
|
conn
|
||||||
|
"
|
||||||
|
SELECT DISTINCT git_repository_id, name
|
||||||
|
FROM git_branches")))))
|
||||||
|
|
||||||
(define (delete-data-for-all-branches-but-master)
|
(define (delete-data-for-all-branches-but-master)
|
||||||
(with-postgresql-connection
|
(with-postgresql-connection
|
||||||
"data-deletion"
|
"data-deletion"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue