From a5c4d53c09be9eb35925c9814e51d645d6cdd50d Mon Sep 17 00:00:00 2001 From: moveson Date: Thu, 19 Dec 2024 13:14:51 -0700 Subject: [PATCH 1/2] Migrate service_completed_date to service_detail --- .../temp/migrate_completed_service_date.rake | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/tasks/temp/migrate_completed_service_date.rake diff --git a/lib/tasks/temp/migrate_completed_service_date.rake b/lib/tasks/temp/migrate_completed_service_date.rake new file mode 100644 index 000000000..dc0a5b681 --- /dev/null +++ b/lib/tasks/temp/migrate_completed_service_date.rake @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +namespace :temp do + desc "Migrates lottery_entrants.service_completed_date to lotteries_entrant_service_detail.completed_date" + task migrate_service_completed_date: :environment do + puts "Migrating lottery_entrants.service_completed_date to lotteries_entrant_service_detail.completed_date" + + entrants = LotteryEntrant.where.not(service_completed_date: nil) + entrants_count = entrants.count + + puts "Found #{entrants_count} lottery entrants needing migration" + + progress_bar = ::ProgressBar.new(entrants_count) + + entrants.find_each do |entrant| + progress_bar.increment! + + service_detail = entrant.service_detail || entrant.create_service_detail + service_detail.update(completed_date: entrant.service_completed_date) + rescue ActiveRecordError => e + puts "Could not update record for entrant id: #{entrant.id}" + puts e + end + end +end From 9e8fe82782acc21edd7bf59a29f6d3eda80e2f92 Mon Sep 17 00:00:00 2001 From: moveson Date: Thu, 19 Dec 2024 13:17:40 -0700 Subject: [PATCH 2/2] Update madmin resource for entrant service detail --- .../resources/lotteries/entrant_service_detail_resource.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/madmin/resources/lotteries/entrant_service_detail_resource.rb b/app/madmin/resources/lotteries/entrant_service_detail_resource.rb index 516341255..99368e962 100644 --- a/app/madmin/resources/lotteries/entrant_service_detail_resource.rb +++ b/app/madmin/resources/lotteries/entrant_service_detail_resource.rb @@ -7,10 +7,11 @@ class Lotteries::EntrantServiceDetailResource < Madmin::Resource attribute :form_rejected_comments attribute :created_at, form: false attribute :updated_at, form: false - attribute :completed_form, index: false + attribute :completed_date # Associations attribute :entrant + attribute :completed_form, index: false # Uncomment this to customize the display name of records in the admin area. # def self.display_name(record)