discourse-translator/db/migrate/20250313082243_create_translation_indexes.rb
Alan Guo Xiang Tan 5e833a80ad
DEV: Rerun CreateTranslationIndexes migration (#251)
The previous version of the migration is not idempotent and can result
in indexes created but marked as "invalid" by Postgres.

Per postgres documentation:

If a problem arises while scanning the table, such as a deadlock or a
uniqueness violation in a unique index,
the CREATE INDEX command will fail but leave behind an "invalid" index.
This index will be ignored for querying
purposes because it might be incomplete; however it will still consume
update overhead. The recommended recovery
  method in such cases is to drop the index and try again to perform
  CREATE INDEX CONCURRENTLY.
2025-03-14 09:39:10 +08:00

33 lines
927 B
Ruby

# frozen_string_literal: true
class CreateTranslationIndexes < ActiveRecord::Migration[7.2]
disable_ddl_transaction!
def up
remove_index :discourse_translator_topic_translations,
%i[topic_id locale],
unique: true,
algorithm: :concurrently,
if_exists: true
add_index :discourse_translator_topic_translations,
%i[topic_id locale],
unique: true,
algorithm: :concurrently
remove_index :discourse_translator_post_translations,
%i[post_id locale],
unique: true,
algorithm: :concurrently,
if_exists: true
add_index :discourse_translator_post_translations,
%i[post_id locale],
unique: true,
algorithm: :concurrently
end
def down
raise ActiveRecord::IrreversibleMigration
end
end