From cbe7249b67a7449c3a85b29dad951f0342daa9a6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 28 May 2020 14:54:21 +0200 Subject: [PATCH] Fix remaining etablissements with shared dossier --- ...00528124044_fix_dossier_etablissement.rake | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/tasks/deployment/20200528124044_fix_dossier_etablissement.rake diff --git a/lib/tasks/deployment/20200528124044_fix_dossier_etablissement.rake b/lib/tasks/deployment/20200528124044_fix_dossier_etablissement.rake new file mode 100644 index 000000000..3df50df86 --- /dev/null +++ b/lib/tasks/deployment/20200528124044_fix_dossier_etablissement.rake @@ -0,0 +1,20 @@ +namespace :after_party do + desc 'Deployment task: fix_dossier_etablissement' + task fix_dossier_etablissement: :environment do + puts "Running deploy task 'fix_dossier_etablissement'" + + etablissements = Etablissement.joins(:champ).where.not(dossier_id: nil).where('etablissements.created_at > ?', 1.month.ago) + dossiers_modif = [] + etablissements.find_each do |e| + if e.dossier + dossier = e.dossier + e.update!(dossier_id: nil) + dossier.reload.etablissement = e.reload.dup + dossier.save! + dossiers_modif << dossier.id + end + end + puts "Nb dossiers modifiés: #{dossiers_modif.size}" + AfterParty::TaskRecord.create version: '20200528124044' + end +end