2017-02-15 15:26:24 +01:00
|
|
|
class RemoveDuplicateEmailReceived < ActiveRecord::Migration[5.0]
|
|
|
|
def change
|
2017-08-28 11:18:38 +02:00
|
|
|
all_mails = MailReceived.all
|
2018-10-01 14:20:14 +02:00
|
|
|
groupped = all_mails.group_by(&:procedure_id)
|
2018-01-15 19:12:15 +01:00
|
|
|
filtered = groupped.reject { |k, v| v.length < 2 }
|
2018-01-12 13:16:08 +01:00
|
|
|
filtered.each_value do |duplicate_mails|
|
2018-01-15 19:12:15 +01:00
|
|
|
duplicate_mails.pop
|
|
|
|
duplicate_mails.each(&:destroy)
|
|
|
|
end
|
2017-02-15 15:26:24 +01:00
|
|
|
end
|
|
|
|
end
|