tasks: populate Procedure.administrateurs even for hidden procedures (#3822)

Migration des administrateurs des procédures masquées
This commit is contained in:
Pierre de La Morinerie 2019-04-29 16:51:56 +02:00 committed by GitHub
commit ae4d74daab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -1,8 +1,6 @@
require Rails.root.join('lib', 'percentile')
class Procedure < ApplicationRecord
self.ignored_columns = [:administrateur_id]
MAX_DUREE_CONSERVATION = 36
has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy

View file

@ -0,0 +1,19 @@
namespace :after_party do
desc 'Deployment task: add_procedure_administrateur_to_administrateurs_for_hidden_procedures'
task add_procedure_administrateur_to_administrateurs_for_hidden_procedures: :environment do
rake_puts "Running deploy task: 'add_procedure_administrateur_to_administrateurs_for_hidden_procedures'"
hidden_procedures = Procedure.unscoped.hidden.includes(:administrateurs)
progress = ProgressReport.new(hidden_procedures.count)
hidden_procedures.find_each do |procedure|
deprecated_administrateur = Administrateur.find_by(id: procedure.administrateur_id)
if deprecated_administrateur && !procedure.administrateurs.include?(deprecated_administrateur)
procedure.administrateurs << deprecated_administrateur
end
progress.inc
end
progress.finish
AfterParty::TaskRecord.create version: '20190429103024'
end
end