Skip to content

Commit 5e833a8

Browse files
authored
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.
1 parent e974006 commit 5e833a8

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

db/migrate/20250205082402_create_translation_indexes.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
class CreateTranslationIndexes < ActiveRecord::Migration[7.2]
4+
disable_ddl_transaction!
5+
6+
def up
7+
remove_index :discourse_translator_topic_translations,
8+
%i[topic_id locale],
9+
unique: true,
10+
algorithm: :concurrently,
11+
if_exists: true
12+
13+
add_index :discourse_translator_topic_translations,
14+
%i[topic_id locale],
15+
unique: true,
16+
algorithm: :concurrently
17+
18+
remove_index :discourse_translator_post_translations,
19+
%i[post_id locale],
20+
unique: true,
21+
algorithm: :concurrently,
22+
if_exists: true
23+
24+
add_index :discourse_translator_post_translations,
25+
%i[post_id locale],
26+
unique: true,
27+
algorithm: :concurrently
28+
end
29+
30+
def down
31+
raise ActiveRecord::IrreversibleMigration
32+
end
33+
end

0 commit comments

Comments
 (0)