From 06fde4ab2c827f59c18fb9b67ba84df7f69857a0 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 17 Sep 2025 10:07:49 +0100 Subject: [PATCH] Add `data_migrations:fix_vaccination_records_location` This fixes an issue where some vaccination records are currently invalid as they have both a `location_id` and a `location_name`. Jira-Issue: MAV-2016 --- lib/tasks/data_migrations.rake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/tasks/data_migrations.rake diff --git a/lib/tasks/data_migrations.rake b/lib/tasks/data_migrations.rake new file mode 100644 index 0000000000..97eb7bceb7 --- /dev/null +++ b/lib/tasks/data_migrations.rake @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +namespace :data_migrations do + desc "Fix vaccination record locations where both location_id and location_name is set" + task fix_vaccination_record_locations: :environment do + vaccination_records = + VaccinationRecord + .where.not(location_id: nil) + .where.not(location_name: nil) + + puts "#{vaccination_records.count} vaccination records need fixing" + + vaccination_records.update_all(location_id: nil) + end +end