<commit_before>module ServiceObjects
  class UpdateLegacyEmailTable < Base
    DB = Sequel.connect(Settings.ws.db.to_hash)

    def insert(email)
      DB[:email].insert(idnumber: change.biola_id, email: email)
    end

    def insert_and_update(biola_id, old_email, new_email)
      DB[:email].where(idnumber: biola_id, email: old_email).update(primary: 0)
      DB[:email].insert(idnumber: biola_id, email: new_email)
    end

    def ignore?
      !(change.affiliation_added? && !change.university_email_exists?)
    end
  end
end<commit_msg>Update email table if entry exists<commit_after>module ServiceObjects
  class UpdateLegacyEmailTable < Base
    DB = Sequel.connect(Settings.ws.db.to_hash)

    def insert(email)
      DB[:email].insert(idnumber: change.biola_id, email: email)
    end

    def insert_and_update(biola_id, old_email, new_email)
      DB[:email].where(idnumber: biola_id, email: old_email).update(primary: 0)
      if DB[:email].where(idnumber: biola_id, email: new_email).count > 0
        DB[:email].where(idnumber: biola_id, email: new_email).update(primary: 1, expiration_date: "0000-00-00 00:00:00")
      else
        DB[:email].insert(idnumber: biola_id, email: new_email)
      end
    end

    def ignore?
      !(change.affiliation_added? && !change.university_email_exists?)
    end
  end
end
{'fraction_non_alphanumeric': 0.11428571428571428, 'fraction_numerical': 0.013533834586466165, 'mean_word_length': 3.911439114391144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '2133722', 'n_tokens_mistral': 464, 'n_tokens_neox': 443, 'n_words': 90}