guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

07/08: Avoid duplicate build status entries


From: Christopher Baines
Subject: 07/08: Avoid duplicate build status entries
Date: Wed, 1 Jul 2020 04:36:53 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit 5ee82075656609e4b2cd03a304162959147f929c
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Tue Jun 30 18:30:01 2020 +0100

    Avoid duplicate build status entries
    
    This effectively makes adding build status entries idempotent to some 
degree.
---
 guix-data-service/model/build-status.scm        |  4 +++-
 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 +++++++
 5 files changed, 36 insertions(+), 1 deletion(-)

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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]