From 9b39934e8bdec7684f65c549917980369295d36f Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Nov 2018 16:39:14 +0100 Subject: [PATCH 1/2] Destroy dossier_operation_logs when dossier is destroyed --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c1b83f1f0..58ff1328d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -26,7 +26,7 @@ class Dossier < ApplicationRecord has_many :followers_gestionnaires, through: :follows, source: :gestionnaire has_many :avis, dependent: :destroy - has_many :dossier_operation_logs + has_many :dossier_operation_logs, dependent: :destroy belongs_to :procedure belongs_to :user From d11cef6b0ce7f162aeaf01a89bb00a6230fb4b93 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 28 Nov 2018 17:00:28 +0100 Subject: [PATCH 2/2] Add task to cleanup orphaned dossier_operation_logs --- ...destroy_orphaned_dossier_operation_logs.rake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/tasks/deployment/20181128155650_destroy_orphaned_dossier_operation_logs.rake diff --git a/lib/tasks/deployment/20181128155650_destroy_orphaned_dossier_operation_logs.rake b/lib/tasks/deployment/20181128155650_destroy_orphaned_dossier_operation_logs.rake new file mode 100644 index 000000000..82aa61b46 --- /dev/null +++ b/lib/tasks/deployment/20181128155650_destroy_orphaned_dossier_operation_logs.rake @@ -0,0 +1,17 @@ +namespace :after_party do + desc 'Deployment task: destroy_orphaned_dossier_operation_logs' + task destroy_orphaned_dossier_operation_logs: :environment do + bar = RakeProgressbar.new(DossierOperationLog.count) + + DossierOperationLog.find_each do |log| + if log.dossier.blank? + log.destroy + end + bar.inc + end + + bar.finished + + AfterParty::TaskRecord.create version: '20181128155650' + end +end