Merge pull request #7268 from betagouv/fix_wrong_parent
fix(revision) : corrige les liens entre parent enfant
This commit is contained in:
commit
7426e8b16f
1 changed files with 32 additions and 0 deletions
32
lib/tasks/deployment/20220506105510_fix_wrong_parent.rake
Normal file
32
lib/tasks/deployment/20220506105510_fix_wrong_parent.rake
Normal 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
|
Loading…
Reference in a new issue