From 7036a4295d35d804426cfcaa27cf787a527ef1fb Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 4 Mar 2024 16:52:20 +0800 Subject: [PATCH] DEV: Fix migration that adds index to `incoming_emails` `topic_id` (#26007) Why this change? Follow up to f880f1a42ffc39cd65eeaf318682b166290fd1d4. When adding an index concurrently where the database transaction is disabled, we have to ensure that we drop the index first if it exists because an invalid index can be created if the migration has failed before. --- .../20240304030429_topic_id_on_incoming_email_index.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/migrate/20240304030429_topic_id_on_incoming_email_index.rb b/db/migrate/20240304030429_topic_id_on_incoming_email_index.rb index 43d378313d5..535179245f8 100644 --- a/db/migrate/20240304030429_topic_id_on_incoming_email_index.rb +++ b/db/migrate/20240304030429_topic_id_on_incoming_email_index.rb @@ -2,7 +2,12 @@ class TopicIdOnIncomingEmailIndex < ActiveRecord::Migration[7.0] disable_ddl_transaction! - def change + def up + remove_index :incoming_emails, :topic_id, if_exists: true add_index :incoming_emails, :topic_id, algorithm: :concurrently end + + def down + raise ActiveRecord::IrreversibleMigration + end end