-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1350 from SplitTime/oveson/migrate-service-comple…
…ted-date-data Migrate service_completed_date data
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |