mastodon/db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb

25 lines
864 B
Ruby
Raw Normal View History

require Rails.root.join('lib', 'mastodon', 'migration_helpers')
2021-04-25 06:33:28 +02:00
class AddCaseInsensitiveBtreeIndexToTags < ActiveRecord::Migration[5.2]
include Mastodon::MigrationHelpers
2021-04-25 06:33:28 +02:00
disable_ddl_transaction!
def up
begin
safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower_btree ON tags (lower(name) text_pattern_ops)' }
rescue ActiveRecord::StatementInvalid => e
remove_index :tags, name: 'index_tags_on_name_lower_btree'
raise CorruptionError.new('index_tags_on_name_lower_btree') if e.is_a?(ActiveRecord::RecordNotUnique)
raise e
end
2021-04-25 06:33:28 +02:00
remove_index :tags, name: 'index_tags_on_name_lower'
end
def down
safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))' }
remove_index :tags, name: 'index_tags_on_name_lower_btree'
end
end