diff --git a/utilities/project-factory/migration/main/V20240731162600__add_uniqiue_constraint_process_track.sql b/utilities/project-factory/migration/main/V20240731162600__add_uniqiue_constraint_process_track.sql index 13bbc45bce0..d9bfbd0af53 100644 --- a/utilities/project-factory/migration/main/V20240731162600__add_uniqiue_constraint_process_track.sql +++ b/utilities/project-factory/migration/main/V20240731162600__add_uniqiue_constraint_process_track.sql @@ -1,2 +1,10 @@ +-- Step 1: Remove duplicate rows +DELETE FROM eg_cm_campaign_process a +USING health.eg_cm_campaign_process b +WHERE a.id < b.id +AND a.campaignId = b.campaignId +AND a.type = b.type; + +-- Step 2: Add the unique constraint ALTER TABLE eg_cm_campaign_process -ADD CONSTRAINT uq_campaignId_type UNIQUE (campaignId, type); \ No newline at end of file +ADD CONSTRAINT uq_campaignId_type UNIQUE (campaignId, type);