From 9efa45663c3f0c14ad1dd7f30182e67afd4dcb43 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 27 Nov 2018 14:29:52 +1100 Subject: [PATCH] Encode records with special chars as well Using Marshal.dump on the French production database raised an error: Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8 Replacing Marshal with YAML solves the problem. It is also more reliable and human readable. This code was run against the French, Australian and UK production data successfully. --- db/migrate/20181123012635_associate_customers_to_users.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20181123012635_associate_customers_to_users.rb b/db/migrate/20181123012635_associate_customers_to_users.rb index b42739ff68..95fab93677 100644 --- a/db/migrate/20181123012635_associate_customers_to_users.rb +++ b/db/migrate/20181123012635_associate_customers_to_users.rb @@ -29,11 +29,11 @@ class AssociateCustomersToUsers < ActiveRecord::Migration joins("INNER JOIN spree_users ON customers.email = spree_users.email"). where(user_id: nil).all - File.write(backup_file, Marshal.dump(customers)) + File.write(backup_file, YAML.dump(customers)) end def backed_up_customers - Marshal.load(File.read(backup_file)) + YAML.load(File.read(backup_file)) end def backup_file