이응준 2015-04-28
Merge branch 'issue-2290' into 'next'
from pull-request 1559

* refs/heads/issue-2290:
  Reviewers: Remove duplicated rows

Reviewed-by: 채수원 
Reviewed-by: 이응준 
@3781a1cdd1f249bf2d65b0d6dbb0fb2fd31a86c9
app/models/PullRequest.java
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
@@ -147,8 +147,9 @@
     @ManyToMany(cascade = CascadeType.ALL)
     @JoinTable(
         name = "pull_request_reviewers",
-        joinColumns = @JoinColumn(name = "pull_request_id"),
-        inverseJoinColumns = @JoinColumn(name = "user_id")
+        joinColumns = @JoinColumn(name = "pull_request_id", unique = false),
+        inverseJoinColumns = @JoinColumn(name = "user_id", unique = false),
+        uniqueConstraints = @UniqueConstraint(columnNames = {"pull_request_id", "user_id"})
     )
     public Set<User> reviewers = new HashSet<>();
 
 
conf/evolutions/default/101.sql (added)
+++ conf/evolutions/default/101.sql
@@ -0,0 +1,13 @@
+# --- !Ups
+-- remove duplicated rows in pull_request_reviewers table
+create table prr_tmp (pull_request_id bigint, user_id bigint);
+
+insert into prr_tmp (pull_request_id, user_id) select distinct pull_request_id, user_id from pull_request_reviewers;
+
+truncate table pull_request_reviewers;
+
+insert into pull_request_reviewers (pull_request_id, user_id) select pull_request_id, user_id from prr_tmp;
+
+drop table prr_tmp;
+
+# --- !Downs
Add a comment
List