<commit_before><commit_msg>Add a few rake tasks to prune trial DB<commit_after>namespace :trial_prune do
  desc 'Delete applications for an office'
  task :office_applications, [:office_id] => :environment do |_, args|
    office = Office.find(args[:office_id])

    ActiveRecord::Base.transaction do
      office.applications.each do |application|
        application.applicant.delete
        application.detail.delete

        application.benefit_checks.delete_all unless application.benefit_checks.empty?
        application.evidence_check.delete if application.evidence_check
        application.part_payment.delete if application.part_payment
        application.benefit_override.delete if application.benefit_override

        application.delete
      end
    end
  end

  desc 'Delete applications created by a user'
  task :user_applications, [:user_id] => :environment do |_, args|
    user = User.find(args[:user_id])

    ActiveRecord::Base.transaction do
      Application.where(user: user).each do |application|
        application.applicant.delete
        application.detail.delete

        application.benefit_checks.delete_all unless application.benefit_checks.empty?
        application.evidence_check.delete if application.evidence_check
        application.part_payment.delete if application.part_payment
        application.benefit_override.delete if application.benefit_override

        application.delete
      end
    end
  end

  desc 'Delete users with <EMAIL> email'
  task digital_users: :environment do
    User.with_deleted.where('email LIKE ?', <EMAIL>').delete_all
  end
end
{'fraction_non_alphanumeric': 0.074719800747198, 'fraction_numerical': 0.0, 'mean_word_length': 3.6445086705202314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4249681', 'n_tokens_mistral': 450, 'n_tokens_neox': 419, 'n_words': 102}