From efc809c23ef1d38729dea6537169b9cb862bbee5 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 3 Dec 2025 23:46:08 +0100 Subject: [PATCH] Script to fix misassigned tags See https://github.com/basecamp/fizzy/pull/1879 --- script/maintenance/fix_cross_account_taggings.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 script/maintenance/fix_cross_account_taggings.rb diff --git a/script/maintenance/fix_cross_account_taggings.rb b/script/maintenance/fix_cross_account_taggings.rb new file mode 100644 index 000000000..5fe85a271 --- /dev/null +++ b/script/maintenance/fix_cross_account_taggings.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +require_relative "../config/environment" + +cross_account_taggings = Tagging.joins(:tag).where("taggings.account_id != tags.account_id") + +puts "Found #{cross_account_taggings.count} cross-account taggings to fix" + +cross_account_taggings.find_each do |tagging| + correct_tag = tagging.account.tags.find_or_create_by!(title: tagging.tag.title) + tagging.update!(tag: correct_tag) + puts "Fixed tagging #{tagging.id}: reassigned to tag #{correct_tag.id} (#{correct_tag.title})" +end + +puts "Done!"