demarches-normaliennes/lib/tasks/deployment/20221019094123_nullify_commentaire_deleted_instructeurs.rake
Paul Chavard 5be8810da4 fix(dossier): nullify instructeur and expert id on messages when they are deleted
we keep email on the message so it will be used when instructeur or expert are not available
2022-10-19 11:53:10 +02:00

31 lines
1.2 KiB
Ruby

namespace :after_party do
desc 'Deployment task: nullify_commentaire_deleted_instructeurs'
task nullify_commentaire_deleted_instructeurs: :environment do
puts "Running deploy task 'nullify_commentaire_deleted_instructeurs'"
commentaires_without_instructeurs = Commentaire.where.missing(:instructeur).where.not(instructeur_id: nil)
progress = ProgressReport.new(commentaires_without_instructeurs.count)
commentaires_without_instructeurs.in_batches do |commentaires|
count = commentaires.count
commentaires.update_all(instructeur_id: nil)
progress.inc(count)
end
progress.finish
commentaires_without_experts = Commentaire.where.missing(:expert).where.not(expert_id: nil)
progress = ProgressReport.new(commentaires_without_experts.count)
commentaires_without_experts.in_batches do |commentaires|
count = commentaires.count
commentaires.update_all(expert_id: nil)
progress.inc(count)
end
progress.finish
# 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