From dc317afb11bd66f56f887efd35f115a25aaf0fa5 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 27 Aug 2026 08:07:02 +0000 Subject: [PATCH] Make some of 4.7 migrations more resilient to being interrupted (#40264) --- ...5939_add_index_account_id_local_fragment_to_keypair.rb | 8 +++++++- ..._add_new_index_account_id_local_fragment_to_keypair.rb | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/db/migrate/20260629125939_add_index_account_id_local_fragment_to_keypair.rb b/db/migrate/20260629125939_add_index_account_id_local_fragment_to_keypair.rb index 7e25c6adde3..9388b935503 100644 --- a/db/migrate/20260629125939_add_index_account_id_local_fragment_to_keypair.rb +++ b/db/migrate/20260629125939_add_index_account_id_local_fragment_to_keypair.rb @@ -3,7 +3,13 @@ class AddIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1] disable_ddl_transaction! - def change + def up add_index :keypairs, [:account_id, :local_fragment], unique: true, where: 'local_fragment IS NOT NULL', algorithm: :concurrently + rescue ActiveRecord::StatementInvalid + safety_assured { execute 'REINDEX INDEX CONCURRENTLY index_keypairs_on_account_id_and_local_fragment' } + end + + def down + remove_index :keypairs, name: :index_keypairs_on_account_id_and_local_fragment end end diff --git a/db/migrate/20260701161457_add_new_index_account_id_local_fragment_to_keypair.rb b/db/migrate/20260701161457_add_new_index_account_id_local_fragment_to_keypair.rb index 8b5f26ae5ab..984e92c2e1b 100644 --- a/db/migrate/20260701161457_add_new_index_account_id_local_fragment_to_keypair.rb +++ b/db/migrate/20260701161457_add_new_index_account_id_local_fragment_to_keypair.rb @@ -3,7 +3,13 @@ class AddNewIndexAccountIdLocalFragmentToKeypair < ActiveRecord::Migration[8.1] disable_ddl_transaction! - def change + def up add_index :keypairs, [:account_id, :local_fragment], unique: true, name: :index_keypairs_on_account_id_and_local_fragment, algorithm: :concurrently + rescue ActiveRecord::StatementInvalid + safety_assured { execute 'REINDEX INDEX CONCURRENTLY index_keypairs_on_account_id_and_local_fragment' } + end + + def down + remove_index :keypairs, name: :index_keypairs_on_account_id_and_local_fragment end end