Script to merge duplicated tags

This commit is contained in:
Jorge Manrubia
2025-04-07 06:12:08 +02:00
parent 99584a17f4
commit 950aebb409
+23
View File
@@ -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