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 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