From a9c6bc2a283b45630f06633606a03d7a4a7a8544 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 23 Jan 2026 10:57:50 -0500 Subject: [PATCH] Add migration to remove draft cards from search index One-time script to clean up any search records that were indexed before the searchable? guard was added. Co-Authored-By: Claude Opus 4.5 --- ...23-remove-draft-cards-from-search-index.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 script/migrations/20260123-remove-draft-cards-from-search-index.rb diff --git a/script/migrations/20260123-remove-draft-cards-from-search-index.rb b/script/migrations/20260123-remove-draft-cards-from-search-index.rb new file mode 100755 index 000000000..35afd98e8 --- /dev/null +++ b/script/migrations/20260123-remove-draft-cards-from-search-index.rb @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require_relative "../../config/environment" + +total_deleted = 0 + +Account.find_each do |account| + search_record_class = Search::Record.for(account.id) + + # Find search records for draft cards (both Card and Comment searchables) + draft_card_ids = Card.where(account_id: account.id, status: "drafted").pluck(:id) + + if draft_card_ids.any? + count = search_record_class.where(card_id: draft_card_ids).delete_all + if count > 0 + puts "#{account.name}: deleted #{count} search records for draft cards" + total_deleted += count + end + end +end + +puts "Migration completed! Total deleted: #{total_deleted}"