20181207011115_downcase_custom_emoji_domains.rb 509 B

1234567891011121314151617
  1. # frozen_string_literal: true
  2. class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
  3. disable_ddl_transaction!
  4. def up
  5. duplicates = CustomEmoji.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM custom_emojis GROUP BY shortcode, lower(domain) HAVING count(*) > 1').to_ary
  6. duplicates.each do |row|
  7. CustomEmoji.where(id: row['ids'].split(',')[0...-1]).destroy_all
  8. end
  9. CustomEmoji.in_batches.update_all('domain = lower(domain)')
  10. end
  11. def down; end
  12. end