-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9767 from alphagov/convert-to-utf8mb4
Convert all tables to use UTF8MB4 charset
- Loading branch information
Showing
3 changed files
with
185 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
11 changes: 11 additions & 0 deletions
11
db/data_migration/2024121711524600_convert_text_columns_to_utf8mb4.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;" |
Oops, something went wrong.