I'm converting a large (70G) legacy mysql database that is mostly utf8 (but with a sprinkling of other encodings in fields) to one that is (as uniformly as possible) utf8mb4 (utf8mb4_unicode_ci).
The db encoding was utf8, and most tables were utf8. Some fields were a mish-mash of different encodings, which I think is a result of the db being decades old, and are seemingly random/unintentional. There are 350 tables in the db, and all text (or %99+) is in English.
This article gave me a good start on how to go about changing the encodings. The main difficulty was in changing the field sizes for VARCHAR fields that also had an index, so that the sizes worked. Basically this involved changing text fields with an index from VARCHAR(255) to VARCHAR(191).
I made a somewhat crude check for those fields to see what the longest value was and to prevent data loss. It only found one field among hundreds that might have been truncated going from VARCHAR(255) to VARCHAR(191).
def check_for_safe_length(column, table)
return is_length_exception?(column, table)
ap "Checking safety for #{table}##{column}"
connection = Blurb.connection
length_info = connection.execute("SELECT LENGTH(#{column}), #{column} from #{table} ORDER BY LENGTH(#{column}) DESC LIMIT 1").first
ap length_info
return if length_info.blank? || length_info[0].blank?
is_safe = length_info[0] < 191
raise "It might not be safe to modify #{table}##{column}" if !is_safe
end
There were also some MEDIUMTEXT fields I needed to change to TEXT.
So that is the background. My real question is how can I be confident with so much data that there is no loss of data or undesirable character conversions?
If/when I run this conversion script, do user testing, then go live, the backup db will start to diverge from the converted db. At that point, going "back" to the backup will lose whatever data went into the converted version between the time it deployed and the time we realized there was an issue. And that could be days or weeks.
So I'm feeling concerned about my ability to detect data issues. Do I have anything to worry about?
Any suggestions?
Thanks
ALTER
your database and tables. An alternative would be to create a new instance of your database and copy data over.