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.
This commit is contained in:
Christopher Baines 2019-08-04 09:39:40 +01:00
parent 1724bc485f
commit 84197686ce
10 changed files with 313 additions and 38 deletions

View file

@ -19,10 +19,10 @@
"https://example.com/why-license-1"))
(("License 1"
"https://gnu.org/licenses/test-1.html"
"https://example.com/why-license-1")
#f)
("License 2"
"https://gnu.org/licenses/test-2.html"
"https://example.com/why-license-2")))))
#f
#f)))))
(with-postgresql-connection
"test-model-license-set"

View file

@ -17,10 +17,13 @@
"https://example.com/why-license-1"))
(("License 1"
"https://gnu.org/licenses/test-1.html"
"https://example.com/why-license-1")
#f)
("License 2"
"https://gnu.org/licenses/test-2.html"
"https://example.com/why-license-2")))))
#f)
("License 3"
#f
#f)))))
(with-postgresql-connection
"test-model-license"

View file

@ -18,6 +18,15 @@
(home-page "https://example.com")
(location (location "file.scm" 5 0))))
(define mock-inferior-package-foo-2
(mock-inferior-package
(name "foo")
(version "2")
(synopsis "Foo")
(description "Foo description")
(home-page #f)
(location #f)))
(define (test-license-set-ids conn)
(mock
((guix-data-service model license)
@ -46,7 +55,8 @@
(match
(inferior-packages->package-metadata-ids
conn
(list mock-inferior-package-foo)
(list mock-inferior-package-foo
mock-inferior-package-foo-2)
(test-license-set-ids conn))
((x) (string? x))))
#:always-rollback? #t))
@ -57,11 +67,13 @@
(test-equal "inferior-packages->package-metadata-ids"
(inferior-packages->package-metadata-ids
conn
(list mock-inferior-package-foo)
(list mock-inferior-package-foo
mock-inferior-package-foo-2)
(test-license-set-ids conn))
(inferior-packages->package-metadata-ids
conn
(list mock-inferior-package-foo)
(list mock-inferior-package-foo
mock-inferior-package-foo-2)
(test-license-set-ids conn)))
#:always-rollback? #t))))))