Mercurial > hg > soundsoftware-site
annotate .svn/pristine/e9/e98415a2db41aabe4184a766f6897f1f0ee7203f.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | cbb26bc654de |
children |
rev | line source |
---|---|
Chris@909 | 1 class AddProjectsTrackersUniqueIndex < ActiveRecord::Migration |
Chris@909 | 2 def self.up |
Chris@909 | 3 remove_duplicates |
Chris@909 | 4 add_index :projects_trackers, [:project_id, :tracker_id], :name => :projects_trackers_unique, :unique => true |
Chris@909 | 5 end |
Chris@909 | 6 |
Chris@909 | 7 def self.down |
Chris@909 | 8 remove_index :projects_trackers, :name => :projects_trackers_unique |
Chris@909 | 9 end |
Chris@909 | 10 |
Chris@909 | 11 # Removes duplicates in projects_trackers table |
Chris@909 | 12 def self.remove_duplicates |
Chris@909 | 13 Project.find(:all).each do |project| |
Chris@909 | 14 ids = project.trackers.collect(&:id) |
Chris@909 | 15 unless ids == ids.uniq |
Chris@909 | 16 project.trackers.clear |
Chris@909 | 17 project.tracker_ids = ids.uniq |
Chris@909 | 18 end |
Chris@909 | 19 end |
Chris@909 | 20 end |
Chris@909 | 21 end |