Log failed data migrations
In theory, it should never happen, but that's why exceptions exist.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
namespace :globalize do
|
namespace :globalize do
|
||||||
desc "Migrates existing data to translation tables"
|
desc "Migrates existing data to translation tables"
|
||||||
task migrate_data: :environment do
|
task migrate_data: :environment do
|
||||||
|
logger = Logger.new(STDOUT)
|
||||||
|
logger.formatter = proc { |severity, _datetime, _progname, msg| "#{severity} #{msg}\n" }
|
||||||
|
|
||||||
[
|
[
|
||||||
AdminNotification,
|
AdminNotification,
|
||||||
Banner,
|
Banner,
|
||||||
@@ -16,7 +19,7 @@ namespace :globalize do
|
|||||||
SiteCustomization::Page,
|
SiteCustomization::Page,
|
||||||
Widget::Card
|
Widget::Card
|
||||||
].each do |model_class|
|
].each do |model_class|
|
||||||
Logger.new(STDOUT).info "Migrating #{model_class} data"
|
logger.info "Migrating #{model_class} data"
|
||||||
|
|
||||||
fields = model_class.translated_attribute_names
|
fields = model_class.translated_attribute_names
|
||||||
|
|
||||||
@@ -33,7 +36,11 @@ namespace :globalize do
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user