From 5b3a5d6ce3679ab7dff14b47c739d308c52abdb2 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 16 May 2023 19:04:20 +0200 Subject: [PATCH] fix(revision): backfill missing published_at on published revisions --- ..._revision_publiee_without_published_at.rake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/tasks/deployment/20230516152457_fix_procedure_revision_publiee_without_published_at.rake diff --git a/lib/tasks/deployment/20230516152457_fix_procedure_revision_publiee_without_published_at.rake b/lib/tasks/deployment/20230516152457_fix_procedure_revision_publiee_without_published_at.rake new file mode 100644 index 000000000..6adf8bfb1 --- /dev/null +++ b/lib/tasks/deployment/20230516152457_fix_procedure_revision_publiee_without_published_at.rake @@ -0,0 +1,18 @@ +namespace :after_party do + desc 'Deployment task: fix_procedure_revision_publiee_without_published_at' + task fix_procedure_revision_publiee_without_published_at: :environment do + puts "Running deploy task 'fix_procedure_revision_publiee_without_published_at'" + + Procedure.unscoped.publiees_ou_closes.includes(:published_revision).find_each do |procedure| # rubocop:disable DS/Unscoped + next unless procedure.published_revision.published_at.nil? + + rake_puts "Found Procedure##{procedure.id}, set published_at on published revision ##{procedure.published_revision.id}: #{procedure.published_at}" + procedure.published_revision.update!(published_at: procedure.published_at) + end + + # 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