Skip to content

Commit

Permalink
pgconfig: also delete duplicate settingsinfos
Browse files Browse the repository at this point in the history
  • Loading branch information
groldan committed Oct 26, 2024
1 parent 14d83d1 commit c422df1
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,38 @@
* - serviceinfo("@type", workspace)
*/


ALTER TABLE settingsinfo
ADD CONSTRAINT fk_settingsinfo_workspace
FOREIGN KEY (workspace)
REFERENCES workspaceinfo(id)
ON DELETE CASCADE;

CREATE UNIQUE INDEX settingsinfo_workspace_key
ON settingsinfo (workspace)
NULLS NOT DISTINCT;
/*
* Delete possible duplicate settingsinfo by workspace before enforcing uniqueness.
*/
DELETE FROM settingsinfo WHERE id IN( SELECT id FROM (
SELECT id,
ROW_NUMBER() OVER(PARTITION BY workspace ORDER BY id ASC) AS duprow
FROM settingsinfo
) dups
WHERE
dups.duprow > 1);

/*
* Delete possible duplicate serviceinfos by type and workspace before enforcing uniqueness.
*/
DELETE FROM serviceinfo WHERE id IN( select id FROM (
DELETE FROM serviceinfo WHERE id IN( SELECT id FROM (
SELECT id,
ROW_NUMBER() OVER(PARTITION BY "@type", workspace ORDER BY id ASC) AS duprow
FROM serviceinfo
) dups
WHERE
dups.duprow > 1);

ALTER TABLE settingsinfo
ADD CONSTRAINT fk_settingsinfo_workspace
FOREIGN KEY (workspace)
REFERENCES workspaceinfo(id)
ON DELETE CASCADE;

CREATE UNIQUE INDEX settingsinfo_workspace_key
ON settingsinfo (workspace)
NULLS NOT DISTINCT;

ALTER TABLE serviceinfo
ADD CONSTRAINT fk_serviceinfo_workspace
FOREIGN KEY (workspace)
Expand Down

0 comments on commit c422df1

Please sign in to comment.