Mercurial > hg > soundsoftware-site
annotate db/migrate/20130201184705_add_unique_index_on_tokens_value.rb @ 1628:9c5f8e24dadc live tip
Quieten this cron script
author | Chris Cannam |
---|---|
date | Tue, 25 Aug 2020 11:38:49 +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 |