Skip to content

Commit

Permalink
Add rake task to remove invalid user phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-l-brockwell committed Nov 6, 2024
1 parent 1c489b2 commit 49d9312
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/tasks/temprary/remove_invalid_user_phone_numbers.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace :db do
desc "Remove invalid user phone_numbers"
task remove_invalid_user_phone_numbers: :environment do
User.find_each do |user|
invalid = false

if user.phone_number && Phonelib.invalid?(user.phone_number)
user.phone_number = nil
invalid = true
end

if user.company_phone_number && Phonelib.invalid?(user.company_phone_number)
user.company_phone_number = nil
invalid = true
end

user.save! if invalid
end
end
end

0 comments on commit 49d9312

Please sign in to comment.