Skip to content

Switch the MySQL adapter from Trilogy to mysql2 - #3240

Open
flavorjones wants to merge 2 commits into
mainfrom
trilogy-to-mysql2
Open

flavorjones wants to merge 2 commits into
mainfrom
trilogy-to-mysql2

Conversation

@flavorjones

@flavorjones flavorjones commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Motivation

Migrating back to mysql2. https://app.basecamp.com/2914079/buckets/1666/card_tables/cards/10439628795

Details

  • Gemfile: mysql2 (~> 0.5) replaces trilogy. config/database.mysql.yml and saas/config/database.yml: adapter: mysql2. mysql2 0.5.7 connects in utf8mb4 by default, as Trilogy does.
  • Code that named the Trilogy adapter now names Mysql2:
    • the UUID type registration, its lookups in MysqlUuidAdapter and Board::Accessible, and the load hook in config/initializers/uuid_primary_keys.rb
    • the sharded-search check in Search::Record
    • ActiveRecordSqlRedaction, which reads a server error's number from Mysql2::Error#error_number. A new test checks that a MySQL server error keeps only its code.
  • saas/config/database.yml names username: root for development and test. With no username, mysql2 connects as the OS user.
  • Remove lib/rails_ext/active_record_trilogy_quote_string.rb, which matched Trilogy's quoting to mysql2's.
  • test/lib/database_adapter_test.rb checks, in MySQL mode, the adapter, a utf8mb4 round trip, and that binary(16) columns are UUIDs.
  • Both Dockerfiles install default-libmysqlclient-dev to build and libmariadb3 to run. The test workflow installs libmysqlclient-dev, and the Brewfile adds mysql-client.

Additional information

What changes for a self-hosted install on MySQL:

  • An install without Docker needs the MySQL client library (libmysqlclient, or MariaDB Connector/C) to build mysql2.
  • In the Docker image, mysql2 links MariaDB Connector/C. MYSQL_SSL_MODE=disabled, required and verify_identity work as before. verify_ca gives a warning and no certificate check.
  • With no connect_timeout set, mysql2 waits up to 120 seconds to connect. The OSS config sets none, as before.

The macOS build of mysql2 against Homebrew's mysql-client is not checked.

Connect to MySQL with mysql2, the driver our other apps use. Register
the UUID type and the MySQL extensions for the Mysql2 adapter, and read
server error numbers from Mysql2::Error#error_number in SQL redaction.
The images, CI and Brewfile install the MySQL client library that
mysql2 links against.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Existing Docker configurations can lose certificate verification, and clean macOS setup lacks the client discovery configuration needed to build mysql2.

2 open issues
What changed in this PR

This PR switches Fizzy’s SaaS and self-hosted MySQL connections from Trilogy to mysql2, aligning the adapter with the other Rails applications.

Changes:

  • Replace the adapter dependency and update UUID handling, search detection, and SQL error redaction.
  • Add native client dependencies for Docker, CI, and macOS.
  • Add adapter compatibility checks and update redaction tests.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
test/​lib/​rails_ext/​active_record_sql_redaction_test.rb Check MySQL error-code preservation during redaction.
test/​lib/​database_adapter_test.rb Check adapter identity, utf8mb4, and UUID typing.
saas/​test/​integration/​structured_log_redaction_test.rb Use mysql2 error messages in redaction tests.
saas/​Dockerfile Install native build and runtime client libraries.
saas/​config/​database.yml Select mysql2 for SaaS connections.
lib/​rails_ext/​active_record_uuid_type.rb Register UUID support for mysql2.
lib/​rails_ext/​active_record_trilogy_quote_string.rb Remove the Trilogy-specific quoting extension.
lib/​rails_ext/​active_record_sql_redaction.rb Read mysql2’s native error numbers.
Gemfile.saas.lock Lock mysql2 in place of Trilogy for SaaS.
Gemfile.lock Lock mysql2 in place of Trilogy.
Gemfile Replace the adapter dependency.
Dockerfile Install native build and runtime client libraries.
config/​initializers/​uuid_primary_keys.rb Update UUID lookup and adapter load hook.
config/​database.mysql.yml Select mysql2 for self-hosted connections.
Brewfile Add the Homebrew MySQL client.
app/​models/​search/​record.rb Recognize mysql2 for sharded search.
app/​models/​board/​accessible.rb Use mysql2’s registered UUID type.
.github/​workflows/​test.yml Install MySQL client development libraries.

Review effort: Balanced

Comment thread config/database.mysql.yml
@@ -1,5 +1,5 @@
default: &default
adapter: trilogy
adapter: mysql2
Comment thread Brewfile
@@ -1,4 +1,5 @@
brew "imagemagick"
brew "mysql-client"
mysql2 connected as the OS user when the config named none, so SaaS
tests could not sign in to MySQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants