<commit_before>class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!

  def change
    CustomEmoji.in_batches.update_all('domain = lower(domain)')
  end
end<commit_msg>Fix unique violation in downcase custom emoji domain migration (#9733)<commit_after>class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!

  def up
    duplicates = CustomEmoji.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM custom_emojis GROUP BY lower(domain) HAVING count(*) > 1').to_hash

    duplicates.each do |row|
      CustomEmoji.where(id: row['ids'].split(',')[0...-1]).destroy_all
    end

    CustomEmoji.in_batches.update_all('domain = lower(domain)')
  end

  def down; end
end
{'fraction_non_alphanumeric': 0.11904761904761904, 'fraction_numerical': 0.01455026455026455, 'mean_word_length': 5.256198347107438, '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': '6099791', 'n_tokens_mistral': 260, 'n_tokens_neox': 255, 'n_words': 50}