From 9e80bda4f91e06e3e1d60cf48d33534b7cabb626 Mon Sep 17 00:00:00 2001
From: Christopher Baines <mail@cbaines.net>
Date: Mon, 5 Aug 2019 20:59:48 +0100
Subject: Avoid erroring when processing emails again

These changes allow processing emails again, and just creating job and branch
entries where data is missing.
---
 ...emove_duplicate_load_new_guix_revision_jobs.sql | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql

(limited to 'sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql')

diff --git a/sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql b/sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql
new file mode 100644
index 0000000..4a5110e
--- /dev/null
+++ b/sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql
@@ -0,0 +1,25 @@
+-- Deploy guix-data-service:remove_duplicate_load_new_guix_revision_jobs to pg
+
+BEGIN;
+
+DELETE FROM load_new_guix_revision_job_events WHERE job_id NOT IN (
+  SELECT MIN(id) FROM load_new_guix_revision_jobs
+  GROUP BY commit, git_repository_id
+);
+
+DELETE FROM load_new_guix_revision_job_logs WHERE job_id NOT IN (
+  SELECT MIN(id) FROM load_new_guix_revision_jobs
+  GROUP BY commit, git_repository_id
+);
+
+DELETE FROM load_new_guix_revision_jobs WHERE id NOT IN (
+  SELECT MIN(id) FROM load_new_guix_revision_jobs
+  GROUP BY commit, git_repository_id
+);
+
+CREATE UNIQUE INDEX ON load_new_guix_revision_jobs (
+  commit,
+  git_repository_id
+);
+
+COMMIT;
-- 
cgit v1.2.3

