aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-12 17:01:51 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-12 18:08:17 +0100
commit8eac26b17d996e3e171c92e43536333daf72b7c9 (patch)
tree72cd6fdf496b4bb5b1c21713fe4395d0dc429623
parent0ab1c71722e81404972f80c91c9717e429d03ec3 (diff)
downloaddata-service-8eac26b17d996e3e171c92e43536333daf72b7c9.tar
data-service-8eac26b17d996e3e171c92e43536333daf72b7c9.tar.gz
Remove the sha1_hash from the package_metadata table
I'm thinking about adding more fields to this table, and the sha1_hash values will make this tricker. Therefore, remove the value, and adjust the existing code to cope. This commit also adds a new test which coveres some of the changed functionality.
-rw-r--r--Makefile.am1
-rw-r--r--guix-data-service/model/package-metadata.scm81
-rw-r--r--sqitch/deploy/remove_package_metadata_sha1_hash.sql7
-rw-r--r--sqitch/revert/remove_package_metadata_sha1_hash.sql7
-rw-r--r--sqitch/sqitch.plan1
-rw-r--r--sqitch/verify/remove_package_metadata_sha1_hash.sql7
-rw-r--r--tests/model-package-metadata.scm37
7 files changed, 97 insertions, 44 deletions
diff --git a/Makefile.am b/Makefile.am
index f9d6062..43248f1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,6 +66,7 @@ TESTS = \
tests/model-derivation.scm \
tests/model-git-branch.scm \
tests/model-git-repository.scm \
+ tests/model-package-metadata.scm \
tests/branch-updated-emails.scm
AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)"
diff --git a/guix-data-service/model/package-metadata.scm b/guix-data-service/model/package-metadata.scm
index bd6cbe6..8578bb1 100644
--- a/guix-data-service/model/package-metadata.scm
+++ b/guix-data-service/model/package-metadata.scm
@@ -8,20 +8,26 @@
#:use-module (guix base16)
#:use-module (guix inferior)
#:use-module (guix-data-service model utils)
- #:export (select-package-metadata
- select-package-metadata-by-revision-name-and-version
- insert-package-metadata
+ #:export (select-package-metadata-by-revision-name-and-version
inferior-packages->package-metadata-ids))
-(define (select-package-metadata hashes)
- (string-append "SELECT id, sha1_hash "
+(define (select-package-metadata package-metadata-values)
+ (string-append "SELECT id, package_metadata.synopsis, "
+ "package_metadata.description, package_metadata.home_page "
"FROM package_metadata "
- "WHERE sha1_hash IN ("
- (string-join (map (lambda (hash)
- (simple-format #f "'~A'" hash))
- hashes)
+ "JOIN (VALUES "
+ (string-join (map (lambda (field-values)
+ (apply
+ simple-format
+ #f "(~A, ~A, ~A)"
+ (map value->quoted-string-or-null
+ field-values)))
+ package-metadata-values)
",")
- ");"))
+ ") AS vals (synopsis, description, home_page) "
+ "ON package_metadata.synopsis = vals.synopsis AND "
+ "package_metadata.description = vals.description AND "
+ "package_metadata.home_page = vals.home_page"))
(define (select-package-metadata-by-revision-name-and-version
conn revision-commit-hash name version)
@@ -48,13 +54,13 @@ WHERE packages.id IN (
(define (insert-package-metadata metadata-rows)
(string-append "INSERT INTO package_metadata "
- "(sha1_hash, synopsis, description, home_page) "
+ "(synopsis, description, home_page) "
"VALUES "
(string-join
(map (match-lambda
- ((sha1_hash synopsis description home_page)
+ ((synopsis description home_page)
(string-append
- "('" sha1_hash "',"
+ "("
(value->quoted-string-or-null synopsis) ","
(value->quoted-string-or-null description) ","
(value->quoted-string-or-null home_page) ")")))
@@ -67,54 +73,41 @@ WHERE packages.id IN (
(define (inferior-packages->package-metadata-ids conn packages)
(define package-metadata
(map (lambda (package)
- (let ((data (list (inferior-package-synopsis package)
- (inferior-package-description package)
- (inferior-package-home-page package))))
- `(,(bytevector->base16-string
- (sha1 (string->utf8
- (string-join
- (map (lambda (d)
- (cond
- ((string? d) d)
- ((boolean? d) (simple-format #f "~A" d))
- (else d)))
- data)
- ":"))))
- ,@data)))
+ (list (inferior-package-synopsis package)
+ (inferior-package-description package)
+ (inferior-package-home-page package)))
packages))
- (define package-metadata-hashes
- (map first package-metadata))
-
(let* ((existing-package-metadata-entries
(exec-query->vhash conn
- (select-package-metadata
- package-metadata-hashes)
- second ;; sha1_hash
+ (select-package-metadata package-metadata)
+ (lambda (results)
+ (cdr (take results 4)))
first)) ;; id))
(missing-package-metadata-entries
(delete-duplicates
(filter (lambda (metadata)
- (not (vhash-assoc (first metadata)
+ (not (vhash-assoc metadata
existing-package-metadata-entries)))
package-metadata)))
(new-package-metadata-entries
(if (null? missing-package-metadata-entries)
'()
- (map car (exec-query conn
- (insert-package-metadata
- missing-package-metadata-entries)))))
+ (map first
+ (exec-query conn
+ (insert-package-metadata
+ missing-package-metadata-entries)))))
(new-entries-id-lookup-vhash
- (two-lists->vhash (map first missing-package-metadata-entries)
+ (two-lists->vhash missing-package-metadata-entries
new-package-metadata-entries)))
- (map (lambda (sha1-hash)
+ (map (lambda (package-metadata-values)
(cdr
- (or (vhash-assoc sha1-hash
+ (or (vhash-assoc package-metadata-values
existing-package-metadata-entries)
- (vhash-assoc sha1-hash
+ (vhash-assoc package-metadata-values
new-entries-id-lookup-vhash)
(begin
- sha1-hash
- (error "missing package-metadata entry")))))
- package-metadata-hashes)))
+ (error "missing package-metadata entry"
+ package-metadata-values)))))
+ package-metadata)))
diff --git a/sqitch/deploy/remove_package_metadata_sha1_hash.sql b/sqitch/deploy/remove_package_metadata_sha1_hash.sql
new file mode 100644
index 0000000..f0bb286
--- /dev/null
+++ b/sqitch/deploy/remove_package_metadata_sha1_hash.sql
@@ -0,0 +1,7 @@
+-- Deploy guix-data-service:remove_package_metadata_sha1_hash to pg
+
+BEGIN;
+
+ALTER TABLE package_metadata DROP COLUMN sha1_hash;
+
+COMMIT;
diff --git a/sqitch/revert/remove_package_metadata_sha1_hash.sql b/sqitch/revert/remove_package_metadata_sha1_hash.sql
new file mode 100644
index 0000000..d2059dc
--- /dev/null
+++ b/sqitch/revert/remove_package_metadata_sha1_hash.sql
@@ -0,0 +1,7 @@
+-- Revert guix-data-service:remove_package_metadata_sha1_hash from pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan
index 9e1c540..026aa7f 100644
--- a/sqitch/sqitch.plan
+++ b/sqitch/sqitch.plan
@@ -7,3 +7,4 @@ buildstatus_enum [appschema] 2019-04-13T11:56:37Z Christopher Baines <mail@cbain
initial_import 2019-04-13T13:06:28Z Christopher Baines <mail@cbaines.net> # Import the manually managed database schema
git_repositories 2019-05-04T19:03:38Z Christopher Baines <mail@cbaines.net> # Add a git_repositories table
git_branches 2019-05-05T14:53:12Z Christopher Baines <mail@cbaines.net> # Add a git_branches table
+remove_package_metadata_sha1_hash 2019-05-12T10:37:40Z Christopher Baines <mail@cbaines.net> # Remove the sha1_hash field from package_metadata
diff --git a/sqitch/verify/remove_package_metadata_sha1_hash.sql b/sqitch/verify/remove_package_metadata_sha1_hash.sql
new file mode 100644
index 0000000..4118a6e
--- /dev/null
+++ b/sqitch/verify/remove_package_metadata_sha1_hash.sql
@@ -0,0 +1,7 @@
+-- Verify guix-data-service:remove_package_metadata_sha1_hash on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;
diff --git a/tests/model-package-metadata.scm b/tests/model-package-metadata.scm
new file mode 100644
index 0000000..4c2bc8e
--- /dev/null
+++ b/tests/model-package-metadata.scm
@@ -0,0 +1,37 @@
+(define-module (test-model-package-metadata)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-64)
+ #:use-module (tests mock-inferior)
+ #:use-module (guix-data-service database))
+
+(test-begin "test-model-package-metadata")
+
+(define mock-inferior-package-foo
+ (mock-inferior-package
+ (name "foo")
+ (version "2")
+ (synopsis "Foo")
+ (description "Foo description")
+ (home-page "https://example.com")))
+
+(with-mock-inferior-packages
+ (lambda ()
+ (use-modules (guix-data-service model package)
+ (guix-data-service model git-repository)
+ (guix-data-service model guix-revision)
+ (guix-data-service model package-metadata))
+
+ (with-postgresql-connection
+ (lambda (conn)
+ (test-assert "inferior-packages->package-metadata-ids"
+ (with-postgresql-transaction
+ conn
+ (lambda (conn)
+ (match
+ (inferior-packages->package-metadata-ids
+ conn
+ (list mock-inferior-package-foo))
+ ((x) (string? x))))
+ #:always-rollback? #t))))))
+
+(test-end)