-
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.
Merge pull request #384 from onc-healthit/LANTERN-595-remove-duplicat…
…es-healthit_products_map Lantern 595 remove duplicates healthit products map
- Loading branch information
Showing
5 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
db/migration/migrations/000028_remove_duplicates_healthit_products_map.down.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,6 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE IF EXISTS public.healthit_products_map DROP CONSTRAINT IF EXISTS unique_id_healthit_product; | ||
|
||
|
||
COMMIT; |
25 changes: 25 additions & 0 deletions
25
db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.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,25 @@ | ||
BEGIN; | ||
|
||
CREATE OR REPLACE FUNCTION delete_duplicate_data_in_healthit_products_map() RETURNS VOID as $$ | ||
BEGIN | ||
WITH CTE AS ( | ||
SELECT | ||
ctid, | ||
ROW_NUMBER() OVER(PARTITION BY id, healthit_product_id ORDER BY id) AS DuplicateCount | ||
FROM | ||
public.healthit_products_map | ||
) | ||
DELETE FROM public.healthit_products_map | ||
WHERE ctid IN ( | ||
SELECT ctid | ||
FROM CTE | ||
WHERE DuplicateCount > 1 | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
SELECT delete_duplicate_data_in_healthit_products_map(); | ||
|
||
ALTER TABLE IF EXISTS public.healthit_products_map ADD CONSTRAINT unique_id_healthit_product UNIQUE (id, healthit_product_id); | ||
|
||
COMMIT; |
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
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