2021-06-02 19:15:17 +02:00
|
|
|
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
|
|
|
|
2021-04-25 06:33:28 +02:00
|
|
|
class AddCaseInsensitiveBtreeIndexToTags < ActiveRecord::Migration[5.2]
|
2021-06-02 19:15:17 +02:00
|
|
|
include Mastodon::MigrationHelpers
|
|
|
|
|
2021-04-25 06:33:28 +02:00
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
2021-06-02 19:15:17 +02:00
|
|
|
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'
|
2022-03-12 08:12:57 +01:00
|
|
|
raise CorruptionError.new('index_tags_on_name_lower_btree') if e.is_a?(ActiveRecord::RecordNotUnique)
|
2021-06-02 19:15:17 +02:00
|
|
|
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
|