diff --git a/script/remove_duplicated_tags.rb b/script/remove_duplicated_tags.rb new file mode 100755 index 000000000..31efade8e --- /dev/null +++ b/script/remove_duplicated_tags.rb @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby + +require_relative "../config/environment" + +ApplicationRecord.with_each_tenant do |tenant| + Account.find_each do |account| + tags_grouped_by_title = account.tags.group_by { |tag| tag.title.downcase } + + tags_grouped_by_title.each do |title, tags| + if tags.length > 1 + to_keep, to_merge = tags.first, tags[1..] + + to_merge.each do |tag_to_merge| + tag_to_merge.bubbles.each do |bubble| + to_keep.bubbles << bubble unless to_keep.bubbles.include?(bubble) + end + + tag_to_merge.destroy + end + end + end + end +end