From 5ee82075656609e4b2cd03a304162959147f929c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 30 Jun 2020 18:30:01 +0100 Subject: Avoid duplicate build status entries This effectively makes adding build status entries idempotent to some degree. --- sqitch/deploy/build_status_add_unique_index.sql | 18 ++++++++++++++++++ sqitch/revert/build_status_add_unique_index.sql | 7 +++++++ sqitch/sqitch.plan | 1 + sqitch/verify/build_status_add_unique_index.sql | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 sqitch/deploy/build_status_add_unique_index.sql create mode 100644 sqitch/revert/build_status_add_unique_index.sql create mode 100644 sqitch/verify/build_status_add_unique_index.sql (limited to 'sqitch') 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 # Support translations for package synopsis and descriptions build_status_nullable_timestamp 2020-06-27T12:34:29Z Christopher Baines # Make build_status.timestamp nullable build_add_build_server_build_id 2020-06-27T12:48:57Z Christopher Baines # Add builds.build_server_build_id +build_status_add_unique_index 2020-06-30T17:19:30Z Christopher Baines # 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; -- cgit v1.2.3