Merge pull request #7268 from betagouv/fix_wrong_parent

fix(revision) : corrige les liens entre parent enfant
This commit is contained in:
LeSim 2022-05-10 14:12:36 +02:00 committed by GitHub
commit 7426e8b16f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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