aboutsummaryrefslogtreecommitdiff
path: root/sqitch/deploy/remove_duplicate_load_new_guix_revision_jobs.sql
blob: 4a5110e4a0b2d79887203e58da1082bac0ff489e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;