-
Notifications
You must be signed in to change notification settings - Fork 6
Force charset to utf8mb4 and utf8mb4_unicode_ci charset/collation #173
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,20 @@ | ||
| base: &base | ||
| encoding: utf8 | ||
| url: <%= ENV.fetch("DATABASE_URL", "trilogy://root@localhost") %> | ||
| default: &default | ||
| adapter: trilogy | ||
| encoding: utf8mb4 # <-- forces UTF-8 everywhere | ||
| collation: utf8mb4_unicode_ci # <-- portable across MySQL 5.7/8.0 and MariaDB | ||
| pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually get slightly nervous about making the pool the same size as the rails thread count ... mostly as it's possible that the rails application logic can (potentially) throw things out to their own background threads ... I'm not really sure just how much this matters, but it's own of those things that makes me :hmmm: |
||
| user: root | ||
| password: | ||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should either be overridable ... or we should have some documentation in here explicitly pointing towards setting the |
||
| host: 127.0.0.1 | ||
| variables: | ||
| # Make sure the session uses utf8mb4 too: | ||
| collation_connection: utf8mb4_unicode_ci | ||
| sql_mode: STRICT_ALL_TABLES | ||
|
|
||
| development: | ||
| <<: *base | ||
| pool: 5 | ||
| <<: *default | ||
| database: awbw_development | ||
|
|
||
| # Warning: The database defined as "test" will be erased and | ||
| # re-generated from your development database when you run "rake". | ||
| # Do not set this db to the same as development or production. | ||
| test: | ||
| <<: *base | ||
| pool: 5 | ||
| <<: *default | ||
| database: awbw_test | ||
|
|
||
| production: | ||
| <<: *base | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| class FixCharsetAndCollation < ActiveRecord::Migration[8.1] | ||
| DB = ActiveRecord::Base.connection_db_config.database | ||
| TARGET = "utf8mb4" | ||
| COLL = "utf8mb4_unicode_ci" | ||
|
|
||
| def up | ||
| execute "ALTER DATABASE `#{DB}` CHARACTER SET #{TARGET} COLLATE #{COLL}" | ||
| tables.each do |t| | ||
| execute "ALTER TABLE `#{t}` CONVERT TO CHARACTER SET #{TARGET} COLLATE #{COLL}" | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| # no-op (irreversible) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def tables | ||
| ActiveRecord::Base.connection.tables - ["schema_migrations", "ar_internal_metadata"] | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍