-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRELLO-2895: fix double consumer review
- Loading branch information
1 parent
5bd9e48
commit 14046a1
Showing
2 changed files
with
20 additions
and
2 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
12 changes: 12 additions & 0 deletions
12
conf/db/migration/default/V54__unique_review_constraint.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,12 @@ | ||
-- Removing duplicates before applying constraint | ||
DELETE | ||
FROM report_consumer_review r | ||
USING (SELECT rr.report_id, MAX(rr.creation_date) AS max_creation | ||
FROM report_consumer_review rr | ||
GROUP BY rr.report_id | ||
HAVING COUNT(1) > 1) agg | ||
WHERE agg.report_id = r.report_id | ||
AND agg.max_creation <> r.creation_date; | ||
|
||
ALTER TABLE report_consumer_review | ||
ADD CONSTRAINT unique_report_id UNIQUE (report_id); |