-
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.
LANTERN-595, LANTERN-596: Removal and prevention of duplicates in hea…
…lthit_products_map
- Loading branch information
1 parent
317fe1b
commit 78b22cc
Showing
3 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
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 public.healthit_products_map DROP CONSTRAINT unique_id_healthit_product; | ||
|
||
|
||
COMMIT; |
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
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(); | ||
|
||
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