Skip to content

Commit

Permalink
Merge pull request #9767 from alphagov/convert-to-utf8mb4
Browse files Browse the repository at this point in the history
Convert all tables to use UTF8MB4 charset
  • Loading branch information
ryanb-gds authored Feb 3, 2025
2 parents 95985ce + 6bab3a5 commit ff06996
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 174 deletions.
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default: &default
encoding: utf8
encoding: utf8mb4
adapter: mysql2
prepared_statements: true
variables:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Convert all tables to utf8mb4 in order to improve support for non-English languages.

connection = ActiveRecord::Base.connection
# Disable foreign key constraints because foreign keys using strings will prevent conversion due to a charset mismatch.
connection.execute "SET foreign_key_checks = 0;"
connection.tables.each do |table|
puts "START: Converting table #{table} to utf8mb4"
connection.execute "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
puts "END: Converted table #{table} to utf8mb4"
end
connection.execute "SET foreign_key_checks = 1;"
Loading

0 comments on commit ff06996

Please sign in to comment.