Skip to content

Commit

Permalink
Add DR2024 venue section migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Oct 29, 2024
1 parent 6ced50e commit 083aae3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/tasks/delegate_report_version.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

DR2024_OLD_EQUIPMENT = "Gen 3 Timers:\nGen 4 Timers:\nGen 5 Timers:\nSpeed Stacks Displays:\nQiYi Displays:\n"

namespace :delegate_reports do
desc "Copy devise_two_factor OTP secret from old format to new format"
desc "Migrate untouched 'legacy' reports to 'dr2024' format"
task migrate_wg2024: [:environment] do
template_report = DelegateReport.new(version: :legacy)
template_report.md_section_defaults!
Expand All @@ -23,4 +25,31 @@ namespace :delegate_reports do
end
end
end

desc "Introduce 'venue' section for reports in 'dr2024' format"
task migrate_wg2024_venue: [:environment] do
template_report = DelegateReport.new(version: :working_group_2024)
template_report.md_section_defaults!

venue_section_template = template_report.venue
.gsub("\r\n", "\n")
.gsub("\r", "\n")

# Only consider reports that haven't been posted yet
DelegateReport.where(posted_at: nil, version: :working_group_2024)
.find_each do |dr|
puts "Migrating #{dr.id} (Competition '#{dr.competition_id}')"

dr.venue = venue_section_template

if dr.equipment.present?
puts " Overriding 'equipment' part in venue section"
dr.venue.gsub!(DR2024_OLD_EQUIPMENT, dr.equipment)
end

dr.equipment = nil

dr.save!
end
end
end

0 comments on commit 083aae3

Please sign in to comment.