From cb71af823120231fc21f693cb722f408732c9de2 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Fri, 21 Nov 2025 11:25:16 +0000 Subject: [PATCH] Remove the old fulltext indexes We only search by account_key, content, and title now. --- ...old_fulltext_indexes_from_search_records.rb | 16 ++++++++++++++++ db/schema.rb | 18 +----------------- 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb 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 new file mode 100644 index 000000000..f9d38dadf --- /dev/null +++ b/db/migrate/20251121112416_remove_old_fulltext_indexes_from_search_records.rb @@ -0,0 +1,16 @@ +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 + (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 + (0..15).each do |shard| + add_index "search_records_#{shard}", [ :content, :title ], type: :fulltext, name: "index_search_records_#{shard}_on_content_and_title" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d94794ed3..f951af36b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do +ActiveRecord::Schema[8.2].define(version: 2025_11_21_112416) do create_table "accesses", id: :uuid, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.datetime "accessed_at" t.uuid "account_id", null: false @@ -420,7 +420,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_0_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_0_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_0_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_0_on_searchable_type_and_searchable_id", unique: true end @@ -436,7 +435,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_1_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_1_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_1_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_1_on_searchable_type_and_searchable_id", unique: true end @@ -452,7 +450,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_10_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_10_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_10_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_10_on_searchable_type_and_searchable_id", unique: true end @@ -468,7 +465,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_11_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_11_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_11_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_11_on_searchable_type_and_searchable_id", unique: true end @@ -484,7 +480,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_12_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_12_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_12_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_12_on_searchable_type_and_searchable_id", unique: true end @@ -500,7 +495,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_13_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_13_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_13_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_13_on_searchable_type_and_searchable_id", unique: true end @@ -516,7 +510,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_14_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_14_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_14_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_14_on_searchable_type_and_searchable_id", unique: true end @@ -532,7 +525,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_15_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_15_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_15_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_15_on_searchable_type_and_searchable_id", unique: true end @@ -548,7 +540,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_2_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_2_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_2_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_2_on_searchable_type_and_searchable_id", unique: true end @@ -564,7 +555,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_3_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_3_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_3_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_3_on_searchable_type_and_searchable_id", unique: true end @@ -580,7 +570,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_4_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_4_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_4_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_4_on_searchable_type_and_searchable_id", unique: true end @@ -596,7 +585,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_5_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_5_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_5_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_5_on_searchable_type_and_searchable_id", unique: true end @@ -612,7 +600,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_6_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_6_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_6_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_6_on_searchable_type_and_searchable_id", unique: true end @@ -628,7 +615,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_7_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_7_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_7_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_7_on_searchable_type_and_searchable_id", unique: true end @@ -644,7 +630,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_8_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_8_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_8_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_8_on_searchable_type_and_searchable_id", unique: true end @@ -660,7 +645,6 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_21_092508) do t.string "title" t.index ["account_id"], name: "index_search_records_9_on_account_id" t.index ["account_key", "content", "title"], name: "index_search_records_9_on_account_key_and_content_and_title", type: :fulltext - t.index ["content", "title"], name: "index_search_records_9_on_content_and_title", type: :fulltext t.index ["searchable_type", "searchable_id"], name: "index_search_records_9_on_searchable_type_and_searchable_id", unique: true end