Clean assign_to duplicates with a rake task
This commit is contained in:
parent
b377d8b538
commit
7fdcc91e0c
1 changed files with 12 additions and 0 deletions
12
lib/tasks/2017_08_01_clean_assign_to.rake
Normal file
12
lib/tasks/2017_08_01_clean_assign_to.rake
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace :'2017_08_01_clean_assign_to' do
|
||||
task clean: :environment do
|
||||
duplicates = AssignTo.group(:gestionnaire_id, :procedure_id).count.select{ |_gestionnaire_id_procedure_id, count| count > 1 }.keys
|
||||
|
||||
duplicate_ids = duplicates.map { |gestionnaire_id, procedure_id| AssignTo.where(gestionnaire_id: gestionnaire_id, procedure_id: procedure_id).pluck(:id) }
|
||||
|
||||
duplicate_ids.each do |ids|
|
||||
ids.pop
|
||||
AssignTo.where(id: ids).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue