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 / db / migrate / 20090312194159_add_projects_trackers_unique_index.rb @ 912:5e80956cc792

History | View | Annotate | Download (605 Bytes)

1
class AddProjectsTrackersUniqueIndex < ActiveRecord::Migration
2
  def self.up
3
    remove_duplicates
4
    add_index :projects_trackers, [:project_id, :tracker_id], :name => :projects_trackers_unique, :unique => true
5
  end
6

    
7
  def self.down
8
    remove_index :projects_trackers, :name => :projects_trackers_unique
9
  end
10

    
11
  # Removes duplicates in projects_trackers table
12
  def self.remove_duplicates
13
    Project.find(:all).each do |project|
14
      ids = project.trackers.collect(&:id)
15
      unless ids == ids.uniq
16
        project.trackers.clear
17
        project.tracker_ids = ids.uniq
18
      end
19
    end
20
  end
21
end