From 04c3739a3d157235971aa8450cb149bdbd1ab8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Vantomme?= Date: Fri, 11 Mar 2022 17:21:02 +0100 Subject: [PATCH] fix(after_party): rescue from PG::UndefinedColumn ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column types_de_champ.procedure_id does not exist fixes: #7036 --- .../20200728150458_fix_cloned_revisions.rake | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/tasks/deployment/20200728150458_fix_cloned_revisions.rake b/lib/tasks/deployment/20200728150458_fix_cloned_revisions.rake index abfb8b23a..715affec7 100644 --- a/lib/tasks/deployment/20200728150458_fix_cloned_revisions.rake +++ b/lib/tasks/deployment/20200728150458_fix_cloned_revisions.rake @@ -5,21 +5,26 @@ namespace :after_party do Procedure.with_discarded.where(aasm_state: :brouillon).where.not(published_revision_id: nil).update_all(published_revision_id: nil) - types_de_champ = TypeDeChamp.joins(:revision).where('types_de_champ.procedure_id != procedure_revisions.procedure_id') - progress = ProgressReport.new(types_de_champ.count) + begin + types_de_champ = TypeDeChamp.joins(:revision).where('types_de_champ.procedure_id != procedure_revisions.procedure_id') + progress = ProgressReport.new(types_de_champ.count) - types_de_champ.find_each do |type_de_champ| - procedure = type_de_champ.procedure ? type_de_champ.procedure : Procedure.with_discarded.find(type_de_champ.procedure_id) - revision_id = procedure.published_revision_id || procedure.draft_revision_id - type_de_champ.update_column(:revision_id, revision_id) - progress.inc + types_de_champ.find_each do |type_de_champ| + procedure = type_de_champ.procedure ? type_de_champ.procedure : Procedure.with_discarded.find(type_de_champ.procedure_id) + revision_id = procedure.published_revision_id || procedure.draft_revision_id + type_de_champ.update_column(:revision_id, revision_id) + progress.inc + end + + progress.finish + rescue ActiveRecord::StatementInvalid, PG::UndefinedColumn => e + warn e.message + puts "Skip deploy task." + ensure + # 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 - - 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