Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all tables to use UTF8MB4 charset #9745

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions db/migrate/20241217115246_convert_text_columns_to_utf8mb4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ConvertTextColumnsToUtf8mb4 < ActiveRecord::Migration[7.1]
def up
# Disable foreign key constraints because foreign keys using strings will prevent conversion
execute "SET foreign_key_checks = 0;"
ActiveRecord::Base.connection.tables.each do |table|
next if table == "schema_migrations"

execute "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
end
execute "SET foreign_key_checks = 1;"
end
end
Loading
Loading