Clean up member_roles if needed.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4370 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-11-06 11:49:45 +00:00
parent c50b611f85
commit b67e4a87e4
1 changed files with 2 additions and 1 deletions

View File

@ -1,6 +1,7 @@
class AddUniqueIndexOnMembers < ActiveRecord::Migration class AddUniqueIndexOnMembers < ActiveRecord::Migration
def self.up def self.up
# Reassign MemberRole rows if needed # Clean and reassign MemberRole rows if needed
MemberRole.delete_all("member_id NOT IN (SELECT id FROM #{Member.table_name})")
MemberRole.update_all("member_id =" + MemberRole.update_all("member_id =" +
" (SELECT min(m2.id) FROM #{Member.table_name} m1, #{Member.table_name} m2" + " (SELECT min(m2.id) FROM #{Member.table_name} m1, #{Member.table_name} m2" +
" WHERE m1.user_id = m2.user_id AND m1.project_id = m2.project_id" + " WHERE m1.user_id = m2.user_id AND m1.project_id = m2.project_id" +