From 9f7ec97fcec8853ee4428106f8c46b3c7e7ecb53 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Tue, 22 Aug 2023 13:48:27 -0400 Subject: [PATCH] Remove old fraud review profile state backfill rake tasks These rake tasks were added as part of the profile state work. They were used to backfill new columns that were added to track the state of a profile with regards to fraud review. The backfills have been successfully completed so we do not need these rake tasks any longer. [skip changelog] --- lib/tasks/backfill_fraud_pending_reason.rake | 78 ------------------- .../backfill_fraud_review_pending_at.rake | 75 ------------------ 2 files changed, 153 deletions(-) delete mode 100644 lib/tasks/backfill_fraud_pending_reason.rake delete mode 100644 lib/tasks/backfill_fraud_review_pending_at.rake diff --git a/lib/tasks/backfill_fraud_pending_reason.rake b/lib/tasks/backfill_fraud_pending_reason.rake deleted file mode 100644 index 7668f62824b..00000000000 --- a/lib/tasks/backfill_fraud_pending_reason.rake +++ /dev/null @@ -1,78 +0,0 @@ -namespace :profiles do - desc 'If a profile is in review or rejected, store the reason it was marked for fraud' - - ## - # Usage: - # - # Print pending updates - # bundle exec rake profiles:backfill_fraud_pending_reason - # - # Commit updates - # bundle exec rake profiles:backfill_fraud_pending_reason UPDATE_PROFILES=true - # - task backfill_fraud_pending_reason: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - update_profiles = ENV['UPDATE_PROFILES'] == 'true' - - profiles = Profile.where( - fraud_pending_reason: nil, - ).where( - 'fraud_review_pending_at IS NOT NULL OR fraud_rejection_at IS NOT NULL', - ) - - profiles.each do |profile| - proofing_component_status = profile.proofing_components&.[]('threatmetrix_review_status') - fraud_pending_reason = case proofing_component_status - when 'review' - 'threatmetrix_review' - when 'reject' - 'threatmetrix_reject' - else - 'threatmetrix_review' - end - - warn "#{profile.id},#{fraud_pending_reason},#{proofing_component_status}" - profile.update!(fraud_pending_reason: fraud_pending_reason) if update_profiles - end - end - - ## - # Usage: - # - # Rollback the above: - # - # export BACKFILL_OUTPUT='' - # bundle exec rake profiles:rollback_backfill_fraud_pending_reason - # - task rollback_backfill_fraud_pending_reason: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - profile_ids = ENV['BACKFILL_OUTPUT'].split("\n").map do |profile_row| - profile_row.split(',').first - end - - warn "Updating #{profile_ids.count} records" - Profile.where(id: profile_ids).update!(fraud_pending_reason: nil) - end - - ## - # Usage: - # bundle exec rake profiles:validate_backfill_fraud_pending_reason - # - task validate_backfill_fraud_pending_reason: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - profiles = Profile.where( - fraud_pending_reason: nil, - ).where( - 'fraud_review_pending_at IS NOT NULL OR fraud_rejection_at IS NOT NULL', - ) - - if profiles.empty? - warn 'fraud_pending_reason backfill was successful' - else - warn "fraud_pending_reason backfill left #{profile.count} rows" - end - end -end diff --git a/lib/tasks/backfill_fraud_review_pending_at.rake b/lib/tasks/backfill_fraud_review_pending_at.rake deleted file mode 100644 index 9b250fbd83c..00000000000 --- a/lib/tasks/backfill_fraud_review_pending_at.rake +++ /dev/null @@ -1,75 +0,0 @@ -namespace :profiles do - desc 'If a profile is in GPO and fraud pending state, move it out of fraud pending state' - - ## - # Usage: - # - # Print pending updates - # bundle exec rake profiles:backfill_fraud_review_pending_at - # - # Commit updates - # bundle exec rake profiles:backfill_fraud_review_pending_at UPDATE_PROFILES=true - # - task backfill_fraud_review_pending_at: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - update_profiles = ENV['UPDATE_PROFILES'] == 'true' - - profiles = Profile.where( - 'fraud_review_pending_at IS NOT NULL OR fraud_rejection_at IS NOT NULL', - ).where.not( - gpo_verification_pending_at: nil, - ) - - profiles.each do |profile| - if profile.fraud_pending_reason.blank? - warn "Profile ##{profile.id} does not have a fraud pending reason!" - break - end - - warn "#{profile.id},#{profile.fraud_review_pending_at},#{profile.fraud_rejection_at}" - profile.update!(fraud_review_pending_at: nil, fraud_rejection_at: nil) if update_profiles - end - end - - ## - # Usage: - # - # Rollback the above: - # - # export BACKFILL_OUTPUT='' - # bundle exec rake profiles:rollback_backfill_fraud_review_pending_at - # - task rollback_backfill_fraud_review_pending_at: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - profile_data = ENV['BACKFILL_OUTPUT'].split("\n").map do |profile_row| - profile_row.split(',') - end - - warn "Updating #{profile_data.count} records" - profile_data.each do |profile_datum| - profile_id, fraud_review_pending_at, fraud_rejection_at = profile_datum - Profile.where(id: profile_id).update!( - fraud_review_pending_at: fraud_review_pending_at, - fraud_rejection_at: fraud_rejection_at, - ) - end - end - - ## - # Usage: - # bundle exec rake profiles:validate_backfill_fraud_review_pending_at - # - task validate_backfill_fraud_review_pending_at: :environment do |_task, _args| - ActiveRecord::Base.connection.execute('SET statement_timeout = 60000') - - profiles = Profile.where( - 'fraud_review_pending_at IS NOT NULL OR fraud_rejection_at IS NOT NULL', - ).where.not( - gpo_verification_pending_at: nil, - ) - - warn "fraud_pending_reason backfill left #{profiles.count} rows" - end -end