From 05a7ec84e2a35e4fa49a7119059d5a4fc6a1f133 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Wed, 12 Nov 2025 15:42:50 +0000 Subject: [PATCH] Make search tables work with UUID references --- app/models/concerns/searchable.rb | 2 +- db/schema.rb | 96 +++++++++++++------------- test/models/comment/searchable_test.rb | 8 +-- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index c22101b52..a4ae98531 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -2,7 +2,7 @@ module Searchable extend ActiveSupport::Concern def self.search_index_table_name(account_id) - "search_index_#{account_id % 16}" + "search_index_#{account_id.to_s.hash.abs % 16}" end included do diff --git a/db/schema.rb b/db/schema.rb index cf1cbaa58..5cc74b296 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -375,11 +375,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_0", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si0_fulltext", type: :fulltext @@ -387,11 +387,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_1", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si1_fulltext", type: :fulltext @@ -399,11 +399,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_10", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si10_fulltext", type: :fulltext @@ -411,11 +411,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_11", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si11_fulltext", type: :fulltext @@ -423,11 +423,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_12", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si12_fulltext", type: :fulltext @@ -435,11 +435,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_13", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si13_fulltext", type: :fulltext @@ -447,11 +447,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_14", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si14_fulltext", type: :fulltext @@ -459,11 +459,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_15", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si15_fulltext", type: :fulltext @@ -471,11 +471,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_2", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si2_fulltext", type: :fulltext @@ -483,11 +483,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_3", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si3_fulltext", type: :fulltext @@ -495,11 +495,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_4", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si4_fulltext", type: :fulltext @@ -507,11 +507,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_5", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si5_fulltext", type: :fulltext @@ -519,11 +519,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_6", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si6_fulltext", type: :fulltext @@ -531,11 +531,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_7", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si7_fulltext", type: :fulltext @@ -543,11 +543,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_8", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si8_fulltext", type: :fulltext @@ -555,11 +555,11 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_12_184932) do end create_table "search_index_9", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "board_id", null: false - t.bigint "card_id", null: false + t.string "board_id", limit: 25, null: false + t.string "card_id", limit: 25, null: false t.text "content" t.datetime "created_at", null: false - t.bigint "searchable_id", null: false + t.string "searchable_id", limit: 25, null: false t.string "searchable_type", null: false t.string "title" t.index ["content", "title"], name: "idx_si9_fulltext", type: :fulltext diff --git a/test/models/comment/searchable_test.rb b/test/models/comment/searchable_test.rb index 48b6d709a..af7860483 100644 --- a/test/models/comment/searchable_test.rb +++ b/test/models/comment/searchable_test.rb @@ -25,14 +25,14 @@ class Comment::SearchableTest < ActiveSupport::TestCase # Comment is indexed on create comment = @card.comments.create!(body: "searchable comment text", creator: @user) result = ActiveRecord::Base.connection.execute( - "SELECT COUNT(*) FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = #{comment.id}" + "SELECT COUNT(*) FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = '#{comment.id}'" ).first[0] assert_equal 1, result # Comment is updated in index comment.update!(body: "updated text") content = ActiveRecord::Base.connection.execute( - "SELECT content FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = #{comment.id}" + "SELECT content FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = '#{comment.id}'" ).first[0] assert_match /updat/, content @@ -40,7 +40,7 @@ class Comment::SearchableTest < ActiveSupport::TestCase comment_id = comment.id comment.destroy result = ActiveRecord::Base.connection.execute( - "SELECT COUNT(*) FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = #{comment_id}" + "SELECT COUNT(*) FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = '#{comment_id}'" ).first[0] assert_equal 0, result @@ -55,7 +55,7 @@ class Comment::SearchableTest < ActiveSupport::TestCase # Comment stores parent card_id and board_id new_comment = @card.comments.create!(body: "test comment", creator: @user) row = ActiveRecord::Base.connection.execute( - "SELECT card_id, board_id FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = #{new_comment.id}" + "SELECT card_id, board_id FROM #{table_name} WHERE searchable_type = 'Comment' AND searchable_id = '#{new_comment.id}'" ).first assert_equal @card.id, row[0] assert_equal @board.id, row[1]