impress/db/migrate/20240229015410_convert_all_tables_to_utf8mb4.rb
Emi Matchu ec6dca1c16 Improve Unicode support, emojis don't crash us anymore lol!
A few pieces here:

1. Convert all tables to `utf8mb4`+`utf8mb4_unicode_520_ci` strings.
2. Configure that as the server's default.
3. Configure the Rails database connection to use this encoding too.

Came together pretty well, whew! This has been a LONG time coming,
`latin1` is NOT a good charset for the year 2024!
2024-02-28 18:54:27 -08:00

164 lines
6.8 KiB
Ruby

class ConvertAllTablesToUtf8mb4 < ActiveRecord::Migration[7.1]
def change
# NOTE: This migration was generated by our `db:utf8_migration` task! It
# read the list of tables, compared them to the desired charset, and
# generated both SQL to convert to utf8mb4 and to reset back!
reversible do |direction|
direction.up do
execute <<-SQL
ALTER TABLE alt_styles CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE auth_servers CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE campaigns CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE closet_hangers CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE closet_lists CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE colors CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE contributions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE donation_features CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE donations CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE item_outfit_relationships CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE items CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE login_cookies CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE modeling_logs CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE neopets_connections CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE outfits CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE parents_swf_assets CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE pet_loads CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE pet_states CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE pet_types CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE pets CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE schema_migrations CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE species CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE swf_assets CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE users CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
execute <<-SQL
ALTER TABLE zones CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci
SQL
end
direction.down do
execute <<-SQL
ALTER TABLE alt_styles CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
SQL
execute <<-SQL
ALTER TABLE auth_servers CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE campaigns CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE closet_hangers CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE closet_lists CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE colors CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE contributions CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE donation_features CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE donations CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE item_outfit_relationships CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE items CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci
SQL
execute <<-SQL
ALTER TABLE login_cookies CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE modeling_logs CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE neopets_connections CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE outfits CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE parents_swf_assets CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci
SQL
execute <<-SQL
ALTER TABLE pet_loads CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE pet_states CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci
SQL
execute <<-SQL
ALTER TABLE pet_types CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci
SQL
execute <<-SQL
ALTER TABLE pets CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE schema_migrations CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
SQL
execute <<-SQL
ALTER TABLE species CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE swf_assets CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci
SQL
execute <<-SQL
ALTER TABLE users CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
execute <<-SQL
ALTER TABLE zones CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci
SQL
end
end
end
end