Merge pull request #1452 from betagouv/moulinette

Remove duplicated assign_tos
This commit is contained in:
gregoirenovel 2018-02-20 15:02:26 +01:00 committed by GitHub
commit 6b476a098d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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