forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
106798 workspaceitem table migration: delete duplicate rows before in…
…troducing uniqueness constraint
- Loading branch information
Koen Pauwels
committed
Dec 17, 2024
1 parent
dae8dc1
commit bd087ec
Showing
4 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
...ge/rdbms/sqlmigration/h2/V7.6_2023.09.18__workspaceitem_add_item_id_unique_constraint.sql
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...ge/rdbms/sqlmigration/h2/V7.6_2024.12.17__workspaceitem_add_item_id_unique_constraint.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- | ||
-- The contents of this file are subject to the license and copyright | ||
-- detailed in the LICENSE and NOTICE files at the root of the source | ||
-- tree and available online at | ||
-- | ||
-- http://www.dspace.org/license/ | ||
-- | ||
|
||
-- In the workspaceitem table, if there are multiple rows referring to the same item ID, keep only the first of them. | ||
WITH dedup AS ( | ||
SELECT item_id, MIN(workspace_item_id) AS workspace_item_id | ||
FROM workspaceitem | ||
GROUP BY item_id | ||
HAVING COUNT(workspace_item_id) > 1 | ||
) | ||
DELETE FROM workspaceitem | ||
USING dedup | ||
WHERE workspaceitem.item_id = dedup.item_id AND workspaceitem.workspace_item_id <> dedup.workspace_item_id; | ||
|
||
-- Identify which rows have duplicates, and compute their replacements. | ||
ALTER TABLE workspaceitem ADD CONSTRAINT unique_item_id UNIQUE(item_id); |
9 changes: 0 additions & 9 deletions
9
...ms/sqlmigration/postgres/V7.6_2023.09.18__workspaceitem_add_item_id_unique_constraint.sql
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...ms/sqlmigration/postgres/V7.6_2024.12.17__workspaceitem_add_item_id_unique_constraint.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- | ||
-- The contents of this file are subject to the license and copyright | ||
-- detailed in the LICENSE and NOTICE files at the root of the source | ||
-- tree and available online at | ||
-- | ||
-- http://www.dspace.org/license/ | ||
-- | ||
|
||
-- In the workspaceitem table, if there are multiple rows referring to the same item ID, keep only the first of them. | ||
WITH dedup AS ( | ||
SELECT item_id, MIN(workspace_item_id) AS workspace_item_id | ||
FROM workspaceitem | ||
GROUP BY item_id | ||
HAVING COUNT(workspace_item_id) > 1 | ||
) | ||
DELETE FROM workspaceitem | ||
USING dedup | ||
WHERE workspaceitem.item_id = dedup.item_id AND workspaceitem.workspace_item_id <> dedup.workspace_item_id; | ||
|
||
-- Enforce uniqueness of item_id in workspaceitem table. | ||
ALTER TABLE workspaceitem ADD CONSTRAINT unique_item_id UNIQUE(item_id); |