fix(annotations-privees): mismatch Champ.type <> TypeDeChamp.type_champ due to buggy rebases

This commit is contained in:
Colin Darie 2023-03-16 14:42:16 +01:00
parent 84271526f3
commit 4ae18af3cd
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 33 additions and 0 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)