diff options
author | Christopher Baines <mail@cbaines.net> | 2020-06-30 18:30:01 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-07-01 09:35:29 +0100 |
commit | 5ee82075656609e4b2cd03a304162959147f929c (patch) | |
tree | e5f332cf278961a1786fe1f2a0c3203bc4695c88 | |
parent | 919255033121c0aeab6c4c16d58359a07b3408b5 (diff) | |
download | data-service-5ee82075656609e4b2cd03a304162959147f929c.tar data-service-5ee82075656609e4b2cd03a304162959147f929c.tar.gz |
Avoid duplicate build status entries
This effectively makes adding build status entries idempotent to some degree.
-rw-r--r-- | guix-data-service/model/build-status.scm | 4 | ||||
-rw-r--r-- | sqitch/deploy/build_status_add_unique_index.sql | 18 | ||||
-rw-r--r-- | sqitch/revert/build_status_add_unique_index.sql | 7 | ||||
-rw-r--r-- | sqitch/sqitch.plan | 1 | ||||
-rw-r--r-- | sqitch/verify/build_status_add_unique_index.sql | 7 |
5 files changed, 36 insertions, 1 deletions
diff --git a/guix-data-service/model/build-status.scm b/guix-data-service/model/build-status.scm index 1a9d7f7..199e8a4 100644 --- a/guix-data-service/model/build-status.scm +++ b/guix-data-service/model/build-status.scm @@ -85,6 +85,8 @@ VALUES " ")"))) data build-ids) - ", "))) + ", ") + " +ON CONFLICT DO NOTHING")) (exec-query conn query '())) diff --git a/sqitch/deploy/build_status_add_unique_index.sql b/sqitch/deploy/build_status_add_unique_index.sql new file mode 100644 index 0000000..0ba5e6c --- /dev/null +++ b/sqitch/deploy/build_status_add_unique_index.sql @@ -0,0 +1,18 @@ +-- Deploy guix-data-service:build_status_add_unique_index to pg + +BEGIN; + +DELETE FROM build_status +WHERE id NOT IN ( + SELECT MIN(id) FROM build_status GROUP BY build_id, timestamp, status +); + +ALTER TABLE build_status +ADD CONSTRAINT build_status_build_id_timestamp_status_unique +UNIQUE (build_id, timestamp, status); + +CREATE UNIQUE INDEX build_status_build_id_status_unique_idx + ON build_status (build_id, status) + WHERE timestamp IS NULL; + +COMMIT; diff --git a/sqitch/revert/build_status_add_unique_index.sql b/sqitch/revert/build_status_add_unique_index.sql new file mode 100644 index 0000000..2f801ee --- /dev/null +++ b/sqitch/revert/build_status_add_unique_index.sql @@ -0,0 +1,7 @@ +-- Revert guix-data-service:build_status_add_unique_index from pg + +BEGIN; + +-- XXX Add DDLs here. + +COMMIT; diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan index f3c4272..318d2c6 100644 --- a/sqitch/sqitch.plan +++ b/sqitch/sqitch.plan @@ -63,3 +63,4 @@ translations_for_lint_checker_descriptions 2020-05-22T19:49:37Z daniela <daniela translations_for_package_synopsis_and_descriptions 2020-06-09T12:42:54Z daniela <daniela@linux-ijv5> # Support translations for package synopsis and descriptions build_status_nullable_timestamp 2020-06-27T12:34:29Z Christopher Baines <mail@cbaines.net> # Make build_status.timestamp nullable build_add_build_server_build_id 2020-06-27T12:48:57Z Christopher Baines <mail@cbaines.net> # Add builds.build_server_build_id +build_status_add_unique_index 2020-06-30T17:19:30Z Christopher Baines <mail@cbaines.net> # Add a unique index to the build_status table diff --git a/sqitch/verify/build_status_add_unique_index.sql b/sqitch/verify/build_status_add_unique_index.sql new file mode 100644 index 0000000..1415c06 --- /dev/null +++ b/sqitch/verify/build_status_add_unique_index.sql @@ -0,0 +1,7 @@ +-- Verify guix-data-service:build_status_add_unique_index on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK; |