Skip to content

Commit

Permalink
Rake task to conform person emails with lottery applicant emails
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 2, 2024
1 parent 0fbb9bc commit e3527cb
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

namespace :maintenance do
desc "Changes people emails to match historical facts emails for lottery applicants"
task historical_facts_conform_applicant_emails: :environment do
puts "Conforming people emails to match historical facts emails for lottery applicants"

people = Person.joins(:historical_facts)
.where(historical_facts: { kind: :lottery_application} )
.where("historical_facts.email is not null and historical_facts.email <> people.email")
.distinct
person_count = people.count

puts "Found #{person_count} people to update"

progress_bar = ::ProgressBar.new(person_count)

people.find_each do |person|
progress_bar.increment!

if person.user_id?
puts "Person #{person.id} has an associated user; skipping"
next
end

fact = person.historical_facts.find_by(kind: :lottery_application)
person.update(email: fact.email)
rescue ActiveRecordError => e
puts "Could not update record for Person id: #{person.id}"
puts e
end
end
end

0 comments on commit e3527cb

Please sign in to comment.