From 0e519679ceb4c421df51dac8787c4b03702e103c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 20 Jun 2019 16:27:49 +0200 Subject: [PATCH] Remove orphaned piece_justificatives --- ..._purge_unattached_piece_justificative.rake | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake diff --git a/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake b/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake new file mode 100644 index 000000000..08d341254 --- /dev/null +++ b/lib/tasks/deployment/20190521131030_purge_unattached_piece_justificative.rake @@ -0,0 +1,21 @@ +namespace :after_party do + desc 'Deployment task: purge_unattached_piece_justificative' + task purge_unattached_piece_justificative: :environment do + puts "Running deploy task 'purge_unattached_piece_justificative'" + + piece_justificatives = PieceJustificative.where(type_de_piece_justificative_id: nil) + progress = ProgressReport.new(piece_justificatives.count) + piece_justificatives.find_each do |pj| + # detach from dossier to ensure we do not trigger touch + pj.update_column(:dossier_id, nil) + pj.remove_content! + pj.destroy + progress.inc + 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: '20190521131030' + end +end