From 3c48059f07c78dbdca69ef2ecea784210af6a17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 17 Oct 2018 03:55:59 +0200 Subject: [PATCH] Log failed data migrations In theory, it should never happen, but that's why exceptions exist. --- lib/tasks/globalize.rake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tasks/globalize.rake b/lib/tasks/globalize.rake index 69e10508e..02c1e5f02 100644 --- a/lib/tasks/globalize.rake +++ b/lib/tasks/globalize.rake @@ -1,6 +1,9 @@ namespace :globalize do desc "Migrates existing data to translation tables" task migrate_data: :environment do + logger = Logger.new(STDOUT) + logger.formatter = proc { |severity, _datetime, _progname, msg| "#{severity} #{msg}\n" } + [ AdminNotification, Banner, @@ -16,7 +19,7 @@ namespace :globalize do SiteCustomization::Page, Widget::Card ].each do |model_class| - Logger.new(STDOUT).info "Migrating #{model_class} data" + logger.info "Migrating #{model_class} data" fields = model_class.translated_attribute_names @@ -33,7 +36,11 @@ namespace :globalize do end end - record.save! + begin + record.save! + rescue ActiveRecord::RecordInvalid + logger.error "Failed to save #{model_class} with id #{record.id}" + end end end end