aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/utils.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-08-04 09:39:40 +0100
committerChristopher Baines <mail@cbaines.net>2019-08-04 09:39:40 +0100
commit84197686ce227b21dae48745f2919a51e070c3c5 (patch)
tree0ed4cc11138628575e490b803e766e8749a337d6 /guix-data-service/model/utils.scm
parent1724bc485f13922d768bc09309a6a7975678c321 (diff)
downloaddata-service-84197686ce227b21dae48745f2919a51e070c3c5.tar
data-service-84197686ce227b21dae48745f2919a51e070c3c5.tar.gz
Fix some duplicated values in tables
The licenses table, along with the package_metadata table had duplicate values. This could happen as the unique constraints on those tables didn't properly account for the nullable fields. The duplicates in those tables also affected the license_sets, packages, package_derivations tables in a similar way. Finally, the guix_revision_package_derivations table was also affected. This commit adds a migration to fix the data, as well as the constraints. THe code to populate the licenses and package_metadata tables is also updated.
Diffstat (limited to 'guix-data-service/model/utils.scm')
-rw-r--r--guix-data-service/model/utils.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/guix-data-service/model/utils.scm b/guix-data-service/model/utils.scm
index 1ece31a..0ce9fea 100644
--- a/guix-data-service/model/utils.scm
+++ b/guix-data-service/model/utils.scm
@@ -5,6 +5,7 @@
#:use-module (squee)
#:export (quote-string
value->quoted-string-or-null
+ non-empty-string-or-false
exec-query->vhash
two-lists->vhash
deduplicate-strings
@@ -18,6 +19,13 @@
(string-append "$STR$" value "$STR$")
"NULL"))
+(define (non-empty-string-or-false s)
+ (if (string? s)
+ (if (string-null? s)
+ #f
+ s)
+ #f))
+
(define (exec-query->vhash conn query field-function value-function)
(fold (lambda (row result)
(vhash-cons (field-function row)