From 067e889cb4c71b9f6669ef7eb349659fac2daf61 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Fri, 14 Nov 2025 08:51:27 +0000 Subject: [PATCH] Make migrations reversible --- ...51113190256_create_search_record_shards.rb | 19 ++++++++++++------- .../20251114084325_drop_search_results.rb | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/db/migrate/20251113190256_create_search_record_shards.rb b/db/migrate/20251113190256_create_search_record_shards.rb index 5b6ee89ce..5afb2ab8e 100644 --- a/db/migrate/20251113190256_create_search_record_shards.rb +++ b/db/migrate/20251113190256_create_search_record_shards.rb @@ -1,7 +1,7 @@ class CreateSearchRecordShards < ActiveRecord::Migration[8.2] SHARD_COUNT = 16 - def up + def change # Create 16 sharded search_records tables SHARD_COUNT.times do |shard_id| create_table "search_records_#{shard_id}", id: :uuid do |t| @@ -22,13 +22,18 @@ class CreateSearchRecordShards < ActiveRecord::Migration[8.2] # Drop old search_index tables SHARD_COUNT.times do |shard_id| - drop_table "search_index_#{shard_id}", if_exists: true - end - end + drop_table "search_index_#{shard_id}", if_exists: true do |t| + 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 - def down - SHARD_COUNT.times do |shard_id| - drop_table "search_records_#{shard_id}" + t.index [:searchable_type, :searchable_id], unique: true, name: "idx_si#{shard_id}_type_id" + t.index [:content, :title], type: :fulltext, name: "idx_si#{shard_id}_fulltext" + end end end end diff --git a/db/migrate/20251114084325_drop_search_results.rb b/db/migrate/20251114084325_drop_search_results.rb index 48e69b5f8..11dbeb5d6 100644 --- a/db/migrate/20251114084325_drop_search_results.rb +++ b/db/migrate/20251114084325_drop_search_results.rb @@ -1,5 +1,7 @@ class DropSearchResults < ActiveRecord::Migration[8.2] def change - drop_table :search_results + drop_table :search_results do |t| + t.timestamps + end end end