DEV: Make recent creation of chat index idempotent (#19603)
This commit is contained in:
parent
f1e808153c
commit
c2a733a95a
|
@ -3,7 +3,20 @@
|
||||||
class AddIndexToChatMessages < ActiveRecord::Migration[7.0]
|
class AddIndexToChatMessages < ActiveRecord::Migration[7.0]
|
||||||
disable_ddl_transaction!
|
disable_ddl_transaction!
|
||||||
|
|
||||||
def change
|
def up
|
||||||
add_index :chat_messages, [:chat_channel_id, :id], where: "deleted_at IS NULL", algorithm: :concurrently
|
# 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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue