Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 14 additions & 13 deletions config/database.yml
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

collation: utf8mb4_unicode_ci # <-- portable across MySQL 5.7/8.0 and MariaDB
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 DATABASE_URL envvar to override with local config. Not everyone knows that's a thing.

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
22 changes: 22 additions & 0 deletions db/migrate/20250914143038_fix_charset_and_collation.rb
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
Loading