fix(data): remove orphaned targeted_user_links

This commit is contained in:
Martin 2022-10-04 13:37:53 +02:00
parent 54a47fadae
commit ba1035bd30

View file

@ -0,0 +1,18 @@
namespace :after_party do
desc 'Deployment task: clean_orphaned_targeted_user_links'
task clean_orphaned_targeted_user_links: :environment do
puts "Running deploy task 'clean_orphaned_targeted_user_links'"
progress = ProgressReport.new(TargetedUserLink.count)
TargetedUserLink.find_each do |tul|
if tul.target_model.nil?
tul.destroy
end
progress.inc
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end