Merge pull request #8769 from colinux/fix-annotations-privees-champ-type-mismatch

Fix: crash d'annotations privées à cause d'une incohérence avec leur type de champ
This commit is contained in:
Colin Darie 2023-03-16 15:55:56 +00:00 committed by GitHub
commit 83a3421537
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 12 deletions

View file

@ -0,0 +1,25 @@
namespace :after_party do
desc 'Deployment task: fix_champ_type_mismatch'
task fix_private_champ_type_mismatch: :environment do
puts "Running deploy task 'fix_champ_type_mismatch'"
champs = Champ.private_only
# count of large champs count is too slow, so we're using an progress approximation based on id
progress = ProgressReport.new(champs.last.id)
champs.includes(:type_de_champ).in_batches.each_record do |champ|
type_champ = champ.type_de_champ.type_champ
expected_type = "Champs::#{type_champ.classify}Champ"
if champ.type != expected_type
puts "Fixing champ #{champ.id} (#{champ.type} -> #{expected_type})"
champ.update_column(:type, expected_type)
end
progress.set(champ.id)
end
progress.finish
end
end

View file

@ -40,6 +40,14 @@ class ProgressReport
end
end
def set(count)
set_progress(count: count)
if @per_10_000 % 10 == 0
print_progress
end
end
def finish
if @count > 0 && @per_10_000 != 10_000
set_progress(total: @count)