mirror of
https://github.com/discourse/discourse.git
synced 2026-08-10 04:58:31 -05:00
DEV: Rerun AddIndexToPostStatComposerColumns migration (#31765)
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.
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddIndexToPostStatComposerColumns < ActiveRecord::Migration[7.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
if !index_exists?(:post_stats, :composer_version)
|
||||
add_index :post_stats, :composer_version, algorithm: :concurrently
|
||||
end
|
||||
if !index_exists?(:post_stats, :writing_device)
|
||||
add_index :post_stats, :writing_device, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :post_stats, :composer_version if index_exists?(:post_stats, :composer_version)
|
||||
remove_index :post_stats, :writing_device if index_exists?(:post_stats, :writing_device)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddIndexToPostStatComposerColumns < ActiveRecord::Migration[7.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
remove_index :post_stats, :composer_version, algorithm: :concurrently, if_exists: true
|
||||
remove_index :post_stats, :writing_device, algorithm: :concurrently, if_exists: true
|
||||
add_index :post_stats, :composer_version, algorithm: :concurrently
|
||||
add_index :post_stats, :writing_device, algorithm: :concurrently
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user