set svn:eol-style native db/migrate/*.rb

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9100 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-03-05 03:55:03 +00:00
parent 865c2b02e5
commit ee54720556
1 changed files with 16 additions and 16 deletions

View File

@ -1,16 +1,16 @@
class AddUniqueIndexToIssueRelations < ActiveRecord::Migration class AddUniqueIndexToIssueRelations < ActiveRecord::Migration
def self.up def self.up
# Remove duplicates # Remove duplicates
IssueRelation.connection.select_values("SELECT r.id FROM #{IssueRelation.table_name} r" + IssueRelation.connection.select_values("SELECT r.id FROM #{IssueRelation.table_name} r" +
" WHERE r.id > (SELECT min(r1.id) FROM #{IssueRelation.table_name} r1 WHERE r1.issue_from_id = r.issue_from_id AND r1.issue_to_id = r.issue_to_id)").each do |i| " WHERE r.id > (SELECT min(r1.id) FROM #{IssueRelation.table_name} r1 WHERE r1.issue_from_id = r.issue_from_id AND r1.issue_to_id = r.issue_to_id)").each do |i|
IssueRelation.delete_all(["id = ?", i]) IssueRelation.delete_all(["id = ?", i])
end end
add_index :issue_relations, [:issue_from_id, :issue_to_id], :unique => true add_index :issue_relations, [:issue_from_id, :issue_to_id], :unique => true
end end
def self.down def self.down
remove_index :issue_relations, :column => [:issue_from_id, :issue_to_id] remove_index :issue_relations, :column => [:issue_from_id, :issue_to_id]
end end
end end