Support SQLite searching

This commit is contained in:
Donal McBreen
2025-11-20 13:40:14 +00:00
parent a2333d9a37
commit bb36b4846f
13 changed files with 925 additions and 37 deletions
@@ -1,5 +1,8 @@
class CreateSearchIndices < ActiveRecord::Migration[8.2]
def up
# Skip for SQLite - it doesn't use these tables
return if connection.adapter_name == "SQLite"
16.times do |i|
create_table "search_index_#{i}".to_sym, id: :uuid, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
t.string :searchable_type, null: false
@@ -17,6 +20,9 @@ class CreateSearchIndices < ActiveRecord::Migration[8.2]
end
def down
# Skip for SQLite - it doesn't use these tables
return if connection.adapter_name == "SQLite"
16.times do |i|
drop_table "search_index_#{i}".to_sym
end
@@ -2,6 +2,9 @@ class CreateSearchRecordShards < ActiveRecord::Migration[8.2]
SHARD_COUNT = 16
def change
# Skip for SQLite - it uses a single search_records table instead
return if connection.adapter_name == "SQLite"
# Create 16 sharded search_records tables
SHARD_COUNT.times do |shard_id|
create_table "search_records_#{shard_id}", id: :uuid do |t|
@@ -0,0 +1,37 @@
class AddSearchRecords < ActiveRecord::Migration[8.2]
def up
return unless connection.adapter_name == "SQLite"
# Create regular table with integer primary key for FTS5 rowid compatibility
create_table :search_records do |t|
t.uuid :account_id, null: false
t.string :searchable_type, null: false
t.uuid :searchable_id, null: false
t.uuid :card_id, null: false
t.uuid :board_id, null: false
t.string :title
t.text :content
t.datetime :created_at, null: false
t.index [:searchable_type, :searchable_id], unique: true
t.index :account_id
end
# Create FTS5 virtual table using Porter stemmer
# No triggers needed - Searchable concern handles sync via callbacks
execute <<-SQL
CREATE VIRTUAL TABLE search_records_fts USING fts5(
title,
content,
tokenize='porter'
)
SQL
end
def down
return unless connection.adapter_name == "SQLite"
execute "DROP TABLE IF EXISTS search_records_fts"
drop_table :search_records, if_exists: true
end
end