about summary refs log tree commit diff
path: root/db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb
blob: 6fa8c0ec4311fa087882cb33f7fdb9da404a2516 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class AddCaseInsensitiveIndexToTags < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!

  def up
    safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))' }
    remove_index :tags, name: 'index_tags_on_name'
    remove_index :tags, name: 'hashtag_search_index'
  end

  def down
    add_index :tags, :name, unique: true, algorithm: :concurrently
    safety_assured { execute 'CREATE INDEX CONCURRENTLY hashtag_search_index ON tags (name text_pattern_ops)' }
    remove_index :tags, name: 'index_tags_on_name_lower'
  end
end