tasks: populate Procedure.administrateurs even for hidden procedures

The previous procedure migration (created in
f7af01e0dc) worked fine, but didn't run
on hidden procedures (due to the default scope).
This commit is contained in:
Pierre de La Morinerie 2019-04-29 11:52:30 +02:00
parent 2425647fef
commit 8bd1064532
2 changed files with 19 additions and 2 deletions

View file

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