Repository navigation
Switch the MySQL adapter from Trilogy to mysql2 - #3240
Open
flavorjones wants to merge 2 commits into
Open
flavorjones wants to merge 2 commits into
flavorjones wants to merge 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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 rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto 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
| @@ -1,5 +1,5 @@ | |||
| default: &default | |||
| adapter: trilogy | |||
| adapter: mysql2 | |||
| @@ -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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation
Migrating back to mysql2. https://app.basecamp.com/2914079/buckets/1666/card_tables/cards/10439628795
Details
Gemfile:mysql2 (~> 0.5)replacestrilogy.config/database.mysql.ymlandsaas/config/database.yml:adapter: mysql2. mysql2 0.5.7 connects inutf8mb4by default, as Trilogy does.MysqlUuidAdapterandBoard::Accessible, and the load hook inconfig/initializers/uuid_primary_keys.rbSearch::RecordActiveRecordSqlRedaction, which reads a server error's number fromMysql2::Error#error_number. A new test checks that a MySQL server error keeps only its code.saas/config/database.ymlnamesusername: rootfor development and test. With no username, mysql2 connects as the OS user.lib/rails_ext/active_record_trilogy_quote_string.rb, which matched Trilogy's quoting to mysql2's.test/lib/database_adapter_test.rbchecks, in MySQL mode, the adapter, a utf8mb4 round trip, and thatbinary(16)columns are UUIDs.default-libmysqlclient-devto build andlibmariadb3to run. The test workflow installslibmysqlclient-dev, and the Brewfile addsmysql-client.Additional information
What changes for a self-hosted install on MySQL:
libmysqlclient, or MariaDB Connector/C) to build mysql2.MYSQL_SSL_MODE=disabled,requiredandverify_identitywork as before.verify_cagives a warning and no certificate check.connect_timeoutset, mysql2 waits up to 120 seconds to connect. The OSS config sets none, as before.The macOS build of mysql2 against Homebrew's
mysql-clientis not checked.