Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LANTERN-595, LANTERN-596: Removal and prevention of duplicates in hea… #383

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
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;
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,7 @@ func (s *Store) DeleteLinksByProduct(ctx context.Context, productID int) error {

func prepareHealthITProductStatements(s *Store) error {
var err error
addHealthITProductMapStatement, err = s.DB.Prepare(`
INSERT INTO healthit_products_map (id, healthit_product_id)
VALUES ($1, $2)
RETURNING id;`)
addHealthITProductMapStatement, err = s.DB.Prepare(`INSERT INTO healthit_products_map (id, healthit_product_id) VALUES ($1, $2) ON CONFLICT (id, healthit_product_id) DO UPDATE SET id=EXCLUDED.id RETURNING id;`)
if err != nil {
return err
}
Expand Down
Loading