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.
This commit is contained in:
Maikel Linke
2018-11-27 14:29:52 +11:00
parent c152da8122
commit 9efa45663c

View File

@@ -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