Skip to content

Commit

Permalink
Add WCIF sanity check in V2->V3 migration (#10278)
Browse files Browse the repository at this point in the history
* Add WCIF sanity check in V2->V3 migration

* Clean wcaRegistrationId out of WCIF diff

* minor fixes

* rubocop

* Use more idiomatic cleanup function

* Sigh...

---------

Co-authored-by: Duncan <[email protected]>
  • Loading branch information
gregorbg and dunkOnIT authored Nov 18, 2024
1 parent b0b3bc4 commit c629fc7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/tasks/registration_version.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# frozen_string_literal: true

# Quick snippet to remove the "wcaRegistrationId" from the WCIF
# This field directly points to our internal DB, so of course it will change.
def clean_wcif_registrations(wcif)
clean_persons = wcif["persons"].map do |person|
reg = person["registration"]
clean_registration = reg&.except("wcaRegistrationId")

person.merge(
"registration" => clean_registration,
)
end

wcif.merge(
"persons" => clean_persons,
)
end

namespace :registration_version do
desc "Migrates a Competition from V1 to V3"
task :migrate_v1_v3, [:competition_id] => [:environment] do |_, args|
Expand Down Expand Up @@ -74,6 +91,9 @@ namespace :registration_version do
end

LogTask.log_task("Migrating Registrations for Competition #{competition_id}") do
wcif_v2 = competition.to_wcif(authorized: true)
wcif_v2 = clean_wcif_registrations(wcif_v2)

ActiveRecord::Base.transaction do
competition.microservice_registrations.wcif_ordered.includes(:payment_intents).each do |registration|
puts "Creating registration for user: #{registration.user_id}"
Expand Down Expand Up @@ -160,6 +180,18 @@ namespace :registration_version do
competition.create_waiting_list(entries: ms_waiting_list.map { |user_id| reg_lookup[user_id] })

competition.registration_version_v3!

wcif_v3 = competition.reload.to_wcif(authorized: true)
wcif_v3 = clean_wcif_registrations(wcif_v3)

unless wcif_v2 == wcif_v3
puts wcif_v2.to_json
puts wcif_v3.to_json

raise "The WCIF output did not match. Logging debug details: First WCIF is v2, second WCIF is v3"
end

puts "WCIF sanity check has completed succesfully. Continuing migration"
end
end
end
Expand Down

0 comments on commit c629fc7

Please sign in to comment.