DEV: Re-apply chat index migration (#29859)

Commit c2a733a95a422837d517a991de04f8462119cc5e was applied to an
existing migration that possibly had already run. Due to this some
discourse instances might not have the correct index.

This change removes the original migration and creates a new one so that
it will actually be applied.

This is the missing index that some sites might not have:
```
Missing Index | CREATE INDEX
index_chat_messages_on_chat_channel_id_and_id ON public.chat_messages
USING btree (chat_channel_id, id) WHERE (deleted_at IS NOT NULL)
```
This commit is contained in:
Blake Erickson
2024-11-20 12:59:07 -07:00
committed by GitHub
parent 8210c4c649
commit 23a7f00524

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
class AddIndexToChatMessagesOnChatChannelId < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
# Transaction has been disabled so we need to clean up the invalid index if index creation timeout
execute <<~SQL
DROP INDEX CONCURRENTLY IF EXISTS index_chat_messages_on_chat_channel_id_and_id
SQL
execute <<~SQL
CREATE INDEX CONCURRENTLY index_chat_messages_on_chat_channel_id_and_id
ON chat_messages (chat_channel_id,id)
WHERE deleted_at IS NOT NULL
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end