Remove duplicated assign_tos

This commit is contained in:
gregoirenovel 2018-02-20 10:57:39 +01:00
parent 56a8070a59
commit 918a34af39

View file

@ -0,0 +1,17 @@
namespace :'2018_02_14_remove_duplicated_assign_tos' do
task remove: :environment do
duplicates = AssignTo.group(:gestionnaire_id, :procedure_id)
.having("COUNT(*) > 1")
.size
.to_a
duplicates.each do |duplicate|
keys = duplicate.first
gestionnaire_id = keys.first
procedure_id = keys.last
assign_tos = AssignTo.where(gestionnaire_id: gestionnaire_id, procedure_id: procedure_id).to_a
assign_tos.shift
assign_tos.each(&:destroy)
end
end
end