Mercurial > hg > soundsoftware-site
annotate db/migrate/20130201184705_add_unique_index_on_tokens_value.rb @ 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 | |
children |
rev | line source |
---|---|
Chris@1295 | 1 class AddUniqueIndexOnTokensValue < ActiveRecord::Migration |
Chris@1295 | 2 def up |
Chris@1295 | 3 say_with_time "Adding unique index on tokens, this may take some time..." do |
Chris@1295 | 4 # Just in case |
Chris@1295 | 5 duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1") |
Chris@1295 | 6 Token.where(:value => duplicates).delete_all |
Chris@1295 | 7 |
Chris@1295 | 8 add_index :tokens, :value, :unique => true, :name => 'tokens_value' |
Chris@1295 | 9 end |
Chris@1295 | 10 end |
Chris@1295 | 11 |
Chris@1295 | 12 def down |
Chris@1295 | 13 remove_index :tokens, :name => 'tokens_value' |
Chris@1295 | 14 end |
Chris@1295 | 15 end |