Script to fix misassigned tags
See https://github.com/basecamp/fizzy/pull/1879
This commit is contained in:
@@ -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!"
|
||||
Reference in New Issue
Block a user