Rake: add tasks to clean followed_dossiers
This commit is contained in:
parent
26cfa6b2e9
commit
490f71856d
1 changed files with 15 additions and 0 deletions
15
lib/tasks/2017_07_18_clean_followed_dossiers.rake
Normal file
15
lib/tasks/2017_07_18_clean_followed_dossiers.rake
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace :'2017_07_18_clean_followed_dossiers' do
|
||||
task clean: :environment do
|
||||
Follow.where(gestionnaire_id: nil).destroy_all
|
||||
Follow.where(dossier_id: nil).destroy_all
|
||||
|
||||
duplicate_follows = Follow.group('gestionnaire_id', 'dossier_id').count.select{ |_gestionnaire_id_dossier_id, count| count > 1 }.keys
|
||||
|
||||
duplicate_ids = duplicate_follows.map { |gestionnaire_id, dossier_id| Follow.where(gestionnaire_id: gestionnaire_id, dossier_id: dossier_id).pluck(:id) }
|
||||
|
||||
duplicate_ids.each do |ids|
|
||||
ids.pop
|
||||
Follow.where(id: ids).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue