Skip to content

Commit efc809c

Browse files
committed
Script to fix misassigned tags
See #1879
1 parent 38d86fb commit efc809c

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative "../config/environment"
4+
5+
cross_account_taggings = Tagging.joins(:tag).where("taggings.account_id != tags.account_id")
6+
7+
puts "Found #{cross_account_taggings.count} cross-account taggings to fix"
8+
9+
cross_account_taggings.find_each do |tagging|
10+
correct_tag = tagging.account.tags.find_or_create_by!(title: tagging.tag.title)
11+
tagging.update!(tag: correct_tag)
12+
puts "Fixed tagging #{tagging.id}: reassigned to tag #{correct_tag.id} (#{correct_tag.title})"
13+
end
14+
15+
puts "Done!"

0 commit comments

Comments
 (0)