diff --git a/lib/tasks/deployment/20230316125244_fix_champ_type_mismatch.rake b/lib/tasks/deployment/20230316125244_fix_champ_type_mismatch.rake new file mode 100644 index 000000000..cacc33e49 --- /dev/null +++ b/lib/tasks/deployment/20230316125244_fix_champ_type_mismatch.rake @@ -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 diff --git a/lib/tasks/task_helper.rb b/lib/tasks/task_helper.rb index 0057a21be..3a8534183 100644 --- a/lib/tasks/task_helper.rb +++ b/lib/tasks/task_helper.rb @@ -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)