Merge pull request #3084 from tchak/destroy_dossier_operation_logs

Destroy dossier_operation_logs when dossier is destroyed
This commit is contained in:
Paul Chavard 2018-11-28 17:16:11 +01:00 committed by GitHub
commit 4befb57971
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

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

View file

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