annotate db/migrate/20130201184705_add_unique_index_on_tokens_value.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents 261b3d9a4903
children
rev   line source
Chris@1464 1 class AddUniqueIndexOnTokensValue < ActiveRecord::Migration
Chris@1464 2 def up
Chris@1464 3 say_with_time "Adding unique index on tokens, this may take some time..." do
Chris@1464 4 # Just in case
Chris@1464 5 duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1")
Chris@1464 6 Token.where(:value => duplicates).delete_all
Chris@1464 7
Chris@1464 8 add_index :tokens, :value, :unique => true, :name => 'tokens_value'
Chris@1464 9 end
Chris@1464 10 end
Chris@1464 11
Chris@1464 12 def down
Chris@1464 13 remove_index :tokens, :name => 'tokens_value'
Chris@1464 14 end
Chris@1464 15 end