To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / b2 / b2da07c5b59f5a76f7942979d584cb5b875f39ed.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (610 Bytes)

1 1296:038ba2d95de8 Chris
class AddUniqueIndexToIssueRelations < ActiveRecord::Migration
2
  def self.up
3
4
    # Remove duplicates
5
    IssueRelation.connection.select_values("SELECT r.id FROM #{IssueRelation.table_name} r" +
6
      " 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|
7
        IssueRelation.delete_all(["id = ?", i])
8
    end
9
10
    add_index :issue_relations, [:issue_from_id, :issue_to_id], :unique => true
11
  end
12
13
  def self.down
14
    remove_index :issue_relations, :column => [:issue_from_id, :issue_to_id]
15
  end
16
end