Deduplicate builds and add a unique index

Duplicate builds could creep in if the code to create them ran concurrently. I
didn't exclude them initially, as I was unsure if there should be such a
restriction, but at least for now, Cuirass builds map exactly to a single
derivation, so use the same restriction here.
This commit is contained in:
Christopher Baines 2019-12-05 14:10:09 +01:00
parent 8a5beb7f88
commit 0291bda98a
4 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,33 @@
-- Deploy guix-data-service:sort_out_duplicate_builds to pg
BEGIN;
DELETE FROM build_status WHERE build_id IN (
SELECT builds.id
FROM builds
INNER JOIN (
SELECT derivation_file_name, MIN(id) AS id
FROM builds
GROUP BY build_server_id, derivation_file_name
HAVING COUNT(DISTINCT id) > 1
) AS min_ids
ON min_ids.derivation_file_name = builds.derivation_file_name AND
min_ids.id != builds.id
);
DELETE FROM builds WHERE id IN (
SELECT builds.id
FROM builds
INNER JOIN (
SELECT derivation_file_name, MIN(id) AS id
FROM builds
GROUP BY build_server_id, derivation_file_name
HAVING COUNT(DISTINCT id) > 1
) AS min_ids
ON min_ids.derivation_file_name = builds.derivation_file_name AND
min_ids.id != builds.id
);
CREATE UNIQUE INDEX ON builds (build_server_id, derivation_file_name);
COMMIT;

View File

@ -0,0 +1,7 @@
-- Revert guix-data-service:sort_out_duplicate_builds from pg
BEGIN;
DROP INDEX builds_build_server_id_derivation_file_name_idx;
COMMIT;

View File

@ -34,3 +34,4 @@ add_index_on_builds_derivation_file_name 2019-12-03T16:23:55Z <chris@phact> #
narinfo_fetch_record 2019-12-03T20:53:28Z <chris@phact> # Add a table to describe fetching a narinfo
change_nars_size_to_bigint 2019-12-04T21:24:21Z <chris@phact> # Change nars.size to bigint
change_nar_urls_size_to_bigint 2019-12-04T21:49:07Z <chris@phact> # Change nar_urls.size to bigint
sort_out_duplicate_builds 2019-12-05T12:43:53Z <chris@phact> # Sort out duplicate builds

View File

@ -0,0 +1,7 @@
-- Verify guix-data-service:sort_out_duplicate_builds on pg
BEGIN;
-- XXX Add verifications here.
ROLLBACK;