after_party: fix wrong parent

This commit is contained in:
simon lehericey 2022-05-06 14:06:00 +02:00 committed by Paul Chavard
parent 4c6e50baf4
commit 62aecd3b2e

View file

@ -0,0 +1,32 @@
namespace :after_party do
desc 'Deployment task: fix_wrong_parent'
task fix_wrong_parent: :environment do
children = ProcedureRevisionTypeDeChamp.where.not(parent_id: nil).includes(:parent)
rake_puts "#{children.count} children to check"
progress = ProgressReport.new(children.count)
misconfigured = children.filter do |child|
progress.inc
child.revision_id != child.parent.revision_id
end
progress.finish
rake_puts "#{misconfigured.count} children to fix"
progress = ProgressReport.new(misconfigured.count)
misconfigured.each do |child|
new_parent = ProcedureRevisionTypeDeChamp.find_by(revision: child.revision, type_de_champ_id: child.parent.type_de_champ_id)
child.update(parent_id: new_parent.id)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end