File: 20130201184705_add_unique_index_on_tokens_value.rb

package info (click to toggle)
redmine 6.0.6%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,104 kB
  • sloc: ruby: 116,318; javascript: 12,885; sh: 460; perl: 303; python: 166; makefile: 30
file content (15 lines) | stat: -rw-r--r-- 515 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class AddUniqueIndexOnTokensValue < ActiveRecord::Migration[4.2]
  def up
    say_with_time "Adding unique index on tokens, this may take some time..." do
      # Just in case
      duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1")
      Token.where(:value => duplicates).delete_all

      add_index :tokens, :value, :unique => true, :name => 'tokens_value'
    end
  end

  def down
    remove_index :tokens, :name => 'tokens_value'
  end
end