From 86d5b9e9fde524195bdc8c25f466730c1039207b Mon Sep 17 00:00:00 2001 From: archita-ekkirala Date: Wed, 14 Aug 2024 14:53:27 -0500 Subject: [PATCH] LANTERN-595: Adding constraint --- .../000028_remove_duplicates_healthit_products_map.up.sql | 2 ++ db/sql/dbsetup.sql | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.sql b/db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.sql index 4b009e670..34e910d26 100644 --- a/db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.sql +++ b/db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.sql @@ -20,4 +20,6 @@ $$ 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; \ No newline at end of file diff --git a/db/sql/dbsetup.sql b/db/sql/dbsetup.sql index d3f2ee32e..b699103f4 100644 --- a/db/sql/dbsetup.sql +++ b/db/sql/dbsetup.sql @@ -131,7 +131,8 @@ CREATE TABLE healthit_products ( CREATE TABLE healthit_products_map ( id SERIAL, - healthit_product_id INT REFERENCES healthit_products(id) ON DELETE SET NULL + healthit_product_id INT REFERENCES healthit_products(id) ON DELETE SET NULL, + CONSTRAINT unique_id_healthit_product UNIQUE(id, healthit_product_id) ); CREATE TABLE certification_criteria (