From e76f159f05f1a6b058a268104ee7941f50c180af Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Fri, 21 Nov 2025 11:44:37 +0000 Subject: [PATCH] Gate search_record shard migrations on adapter type --- .../20251121092508_add_account_key_to_search_records.rb | 4 ++++ ...2416_remove_old_fulltext_indexes_from_search_records.rb | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/db/migrate/20251121092508_add_account_key_to_search_records.rb b/db/migrate/20251121092508_add_account_key_to_search_records.rb index 8960f56bc..83aaf1988 100644 --- a/db/migrate/20251121092508_add_account_key_to_search_records.rb +++ b/db/migrate/20251121092508_add_account_key_to_search_records.rb @@ -1,5 +1,7 @@ class AddAccountKeyToSearchRecords < ActiveRecord::Migration[8.2] def up + return if ActiveRecord::Base.connection.adapter_name == "SQLite" + 16.times do |shard_id| table_name = "search_records_#{shard_id}" @@ -9,6 +11,8 @@ class AddAccountKeyToSearchRecords < ActiveRecord::Migration[8.2] end def down + return if ActiveRecord::Base.connection.adapter_name == "SQLite" + 16.times do |shard_id| table_name = "search_records_#{shard_id}" diff --git a/db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb b/db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb index f9d38dadf..1fbd67a28 100644 --- a/db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb +++ b/db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb @@ -1,14 +1,15 @@ class RemoveOldFulltextIndexesFromSearchRecords < ActiveRecord::Migration[8.2] def up - # Remove the old fulltext indexes (content, title) from all 16 search_records shards - # We're keeping the new indexes (account_key, content, title) for tenant-aware searching + return if ActiveRecord::Base.connection.adapter_name == "SQLite" + (0..15).each do |shard| remove_index "search_records_#{shard}", name: "index_search_records_#{shard}_on_content_and_title" end end def down - # Re-create the old fulltext indexes in case we need to rollback + return if ActiveRecord::Base.connection.adapter_name == "SQLite" + (0..15).each do |shard| add_index "search_records_#{shard}", [ :content, :title ], type: :fulltext, name: "index_search_records_#{shard}_on_content_and_title" end