]> cat aescling's git repositories - mastodon.git/commitdiff
Fix unique violation in downcase custom emoji domain migration (#9733)
authorEugen Rochko <eugen@zeonfederated.com>
Sun, 6 Jan 2019 22:53:46 +0000 (23:53 +0100)
committerGitHub <noreply@github.com>
Sun, 6 Jan 2019 22:53:46 +0000 (23:53 +0100)
Fix #9727

db/migrate/20181207011115_downcase_custom_emoji_domains.rb

index c9db3800daa36c506bc7fd094d275d7d0495c246..1fce2cb37981315f94550d22b9cad0a71679ef3b 100644 (file)
@@ -1,7 +1,15 @@
 class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
   disable_ddl_transaction!
 
-  def change
+  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