Skip to content

Commit

Permalink
Merge pull request #1350 from SplitTime/oveson/migrate-service-comple…
Browse files Browse the repository at this point in the history
…ted-date-data

Migrate service_completed_date data
  • Loading branch information
moveson authored Dec 19, 2024
2 parents 6275384 + 9e8fe82 commit 7fe80e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions lib/tasks/temp/migrate_completed_service_date.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7fe80e8

Please sign in to comment.