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 / 20130201184705_add_unique_index_on_tokens_value.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (512 Bytes)

1 1295:622f24f53b42 Chris
class AddUniqueIndexOnTokensValue < ActiveRecord::Migration
2
  def up
3
    say_with_time "Adding unique index on tokens, this may take some time..." do
4
      # Just in case
5
      duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1")
6
      Token.where(:value => duplicates).delete_all
7
8
      add_index :tokens, :value, :unique => true, :name => 'tokens_value'
9
    end
10
  end
11
12
  def down
13
    remove_index :tokens, :name => 'tokens_value'
14
  end
15
end