From ff806782de04c3695d7b267e61bf93742a3822a1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 12 Jan 2022 20:00:59 +0100 Subject: [PATCH] feat(attestation): migration task to revise attestations --- ...12184331_revise_attestation_templates.rake | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/tasks/deployment/20220112184331_revise_attestation_templates.rake diff --git a/lib/tasks/deployment/20220112184331_revise_attestation_templates.rake b/lib/tasks/deployment/20220112184331_revise_attestation_templates.rake new file mode 100644 index 000000000..9478bb490 --- /dev/null +++ b/lib/tasks/deployment/20220112184331_revise_attestation_templates.rake @@ -0,0 +1,23 @@ +namespace :after_party do + desc 'Deployment task: moving Attestations from Procedure to ProcedureRevision' + task revise_attestation_templates: :environment do + rake_puts "Running deploy task 'revise_attestation_templates'" + + attestation_templates = AttestationTemplate.where.not(procedure_id: nil) + progress = ProgressReport.new(attestation_templates.count) + + attestation_templates.find_each do |attestation_template| + ProcedureRevision + .where(procedure_id: attestation_template.procedure_id, attestation_template_id: nil) + .update_all(attestation_template_id: attestation_template) + attestation_template.update_column(:procedure_id, nil) + progress.inc + end + progress.finish + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end