aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/jobs
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-11-09 08:30:02 +0000
committerChristopher Baines <mail@cbaines.net>2019-11-09 08:30:02 +0000
commit5bb4dfdabea34af0bfa03d6430935124f7b60a90 (patch)
tree721c0f53ab02ee73365ae9185ed96da0693ae8a1 /guix-data-service/jobs
parentfea4dc9385f6f42e7b89f1fafe1a8189f62af9eb (diff)
downloaddata-service-wip-derivation-history.tar
data-service-wip-derivation-history.tar.gz
Diffstat (limited to 'guix-data-service/jobs')
-rw-r--r--guix-data-service/jobs/load-new-guix-revision.scm72
1 files changed, 71 insertions, 1 deletions
diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm
index 86c3a78..643df0a 100644
--- a/guix-data-service/jobs/load-new-guix-revision.scm
+++ b/guix-data-service/jobs/load-new-guix-revision.scm
@@ -975,6 +975,75 @@ ORDER BY packages.name, packages.version"
#t)
+(define (update-package-derivations-table conn git-repository-id commit)
+ ;; Lock the table to wait for other transactions to commit before updating
+ ;; the table
+ (exec-query
+ conn
+ "
+LOCK TABLE ONLY package_derivations_by_guix_revision_range
+ IN SHARE ROW EXCLUSIVE MODE")
+
+ (for-each
+ (match-lambda
+ ((branch-name)
+ (log-time
+ (simple-format #f "deleting package derivation entries for ~A" branch-name)
+ (lambda ()
+ (exec-query
+ conn
+ "
+DELETE FROM package_derivations_by_guix_revision_range
+WHERE git_repository_id = $1 AND branch_name = $2"
+ (list git-repository-id
+ branch-name))))
+ (log-time
+ (simple-format #f "inserting package derivation entries for ~A" branch-name)
+ (lambda ()
+ (exec-query
+ conn
+ "
+INSERT INTO package_derivations_by_guix_revision_range
+SELECT DISTINCT
+ $1::integer AS git_repository_id,
+ $2 AS branch_name,
+ packages.name AS package_name,
+ packages.version AS package_version,
+ revision_packages.derivation_id AS derivation_id,
+ revision_packages.system AS system,
+ revision_packages.target AS target,
+ first_value(guix_revisions.id)
+ OVER package_version AS first_guix_revision_id,
+ last_value(guix_revisions.id)
+ OVER package_version AS last_guix_revision_id
+FROM packages
+INNER JOIN (
+ SELECT DISTINCT package_derivations.package_id,
+ package_derivations.derivation_id,
+ package_derivations.system,
+ package_derivations.target,
+ guix_revision_package_derivations.revision_id
+ FROM package_derivations
+ INNER JOIN guix_revision_package_derivations
+ ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
+) AS revision_packages ON packages.id = revision_packages.package_id
+INNER JOIN guix_revisions ON revision_packages.revision_id = guix_revisions.id
+INNER JOIN git_branches ON guix_revisions.commit = git_branches.commit
+WHERE git_branches.name = $2
+WINDOW package_version AS (
+ PARTITION BY packages.name, packages.version, revision_packages.derivation_id
+ ORDER BY git_branches.datetime
+ RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+)
+ORDER BY packages.name, packages.version"
+ (list git-repository-id branch-name))))))
+ (exec-query
+ conn
+ "SELECT name FROM git_branches WHERE commit = $1 AND git_repository_id = $2"
+ (list commit git-repository-id)))
+
+ #t)
+
(define (load-new-guix-revision conn git-repository-id commit)
(let ((store-item
(store-item-for-git-repository-id-and-commit
@@ -983,7 +1052,8 @@ ORDER BY packages.name, packages.version"
(and
(extract-information-from conn git-repository-id
commit store-item)
- (update-package-versions-table conn git-repository-id commit))
+ (update-package-versions-table conn git-repository-id commit)
+ (update-package-derivations-table conn git-repository-id commit))
(begin
(simple-format #t "Failed to generate store item for ~A\n"
commit)