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

Introduce adapter for Trilogy, a MySQL-compatible DB client #47880

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

adrianna-chang-shopify
Copy link
Contributor

Motivation / Background

The Trilogy database client and corresponding Active Record adapter were both open sourced by GitHub last year. Shopify adopted Trilogy successfully in our Rails monolith several weeks ago.

With two major Rails applications running Trilogy successfully, we'd like to propose upstreaming the adapter to Rails as a MySQL-compatible alternative to Mysql2Adapter.

This effort is a collaboration between @adrianna-chang-shopify and @eileencodes (Shopify) and @matthewd (GitHub). Original authors of the adapter library are credited.

Detail

This PR ports over the adapter code and all of the test cases from https:/github/activerecord-trilogy-adapter. We can DRY some of the code up between Trilogy and the existing Mysql2 adapter, but I'm proposing we copy everything verbatim for now to ensure full test coverage, and clean things up in a subsequent PR.

Additional changes made:

  • Added options support to #explain on the TrilogyAdapter for parity with Mysql2
  • Database generator supports trilogy option for applications
  • Migration compatibility added for Trilogy
  • TrilogyAdapter#select_all updated to ensure connection returned to a good state after MULTI_RESULT query
  • Active Record Rakefile updated to run abstract MySQL test cases against Trilogy

Additional information

This is blocked by trilogy-libraries/trilogy#64 on the client side. Once that ships, we should release a new version of the client and update the Gemfile to match.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@eileencodes eileencodes self-assigned this Apr 6, 2023
@eileencodes eileencodes added this to the 7.1.0 milestone Apr 6, 2023
eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 7, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.
eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 7, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.
eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 7, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.
@zzak
Copy link
Member

zzak commented Apr 8, 2023

tumblr_m0i88xhqiM1qjgw3wo1_500

Thanks everyone who contributed! This is definitely better than the prequel.

eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 10, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.
@eileencodes
Copy link
Member

Ok the trilogy build is working now, and I fixed some Railties tests. We're green here but locally I noticed a couple flakey tests in mysql2 and trilogy (same ones) regarding closed connections. If I get a chance I'll take a deeper look but I'm not sure they are flaky on CI - might just be locally.

@eileencodes
Copy link
Member

We're green here but locally I noticed a couple flakey tests in mysql2 and trilogy (same ones) regarding closed connections

I can't reproduce this now so it must have been something else wrong. So I think other then the encoding work this is good to go. I asked the rest of core to take a look to make sure I'm not missing anything. Great work @adrianna-chang-shopify!

@adrianna-chang-shopify
Copy link
Contributor Author

Encoding work is shipped! We should also ship the changes to the SyscallErrors in the client to make sure all of the client errors can be rescued as Trilogy::Error.

@adrianna-chang-shopify adrianna-chang-shopify force-pushed the ac-trilogy-adapter branch 3 times, most recently from 13604c6 to 224d03e Compare April 17, 2023 15:32
The [Trilogy database client][trilogy-client] and corresponding
[Active Record adapter][ar-adapter] were both open sourced by GitHub last year.

Shopify has recently taken the plunge and successfully adopted Trilogy in their Rails monolith.
With two major Rails applications running Trilogy successfully, we'd like to propose upstreaming the adapter
to Rails as a MySQL-compatible alternative to Mysql2Adapter.

[trilogy-client]: https:/github/trilogy
[ar-adapter]: https:/github/activerecord-trilogy-adapter

Co-authored-by: Aaron Patterson <[email protected]>
Co-authored-by: Adam Roben <[email protected]>
Co-authored-by: Ali Ibrahim <[email protected]>
Co-authored-by: Aman Gupta <[email protected]>
Co-authored-by: Arthur Nogueira Neves <[email protected]>
Co-authored-by: Arthur Schreiber <[email protected]>
Co-authored-by: Ashe Connor <[email protected]>
Co-authored-by: Brandon Keepers <[email protected]>
Co-authored-by: Brian Lopez <[email protected]>
Co-authored-by: Brooke Kuhlmann <[email protected]>
Co-authored-by: Bryana Knight <[email protected]>
Co-authored-by: Carl Brasic <[email protected]>
Co-authored-by: Chris Bloom <[email protected]>
Co-authored-by: Cliff Pruitt <[email protected]>
Co-authored-by: Daniel Colson <[email protected]>
Co-authored-by: David Calavera <[email protected]>
Co-authored-by: David Celis <[email protected]>
Co-authored-by: David Ratajczak <[email protected]>
Co-authored-by: Dirkjan Bussink <[email protected]>
Co-authored-by: Eileen Uchitelle <[email protected]>
Co-authored-by: Enrique Gonzalez <[email protected]>
Co-authored-by: Garrett Bjerkhoel <[email protected]>
Co-authored-by: Georgi Knox <[email protected]>
Co-authored-by: HParker <[email protected]>
Co-authored-by: Hailey Somerville <[email protected]>
Co-authored-by: James Dennes <[email protected]>
Co-authored-by: Jane Sternbach <[email protected]>
Co-authored-by: Jess Bees <[email protected]>
Co-authored-by: Jesse Toth <[email protected]>
Co-authored-by: Joel Hawksley <[email protected]>
Co-authored-by: John Barnette <[email protected]>
Co-authored-by: John Crepezzi <[email protected]>
Co-authored-by: John Hawthorn <[email protected]>
Co-authored-by: John Nunemaker <[email protected]>
Co-authored-by: Jonathan Hoyt <[email protected]>
Co-authored-by: Katrina Owen <[email protected]>
Co-authored-by: Keeran Raj Hawoldar <[email protected]>
Co-authored-by: Kevin Solorio <[email protected]>
Co-authored-by: Leo Correa <[email protected]>
Co-authored-by: Lizz Hale <[email protected]>
Co-authored-by: Lorin Thwaits <[email protected]>
Co-authored-by: Matt Jones <[email protected]>
Co-authored-by: Matthew Draper <[email protected]>
Co-authored-by: Max Veytsman <[email protected]>
Co-authored-by: Nathan Witmer <[email protected]>
Co-authored-by: Nick Holden <[email protected]>
Co-authored-by: Paarth Madan <[email protected]>
Co-authored-by: Patrick Reynolds <[email protected]>
Co-authored-by: Rob Sanheim <[email protected]>
Co-authored-by: Rocio Delgado <[email protected]>
Co-authored-by: Sam Lambert <[email protected]>
Co-authored-by: Shay Frendt <[email protected]>
Co-authored-by: Shlomi Noach <[email protected]>
Co-authored-by: Sophie Haskins <[email protected]>
Co-authored-by: Thomas Maurer <[email protected]>
Co-authored-by: Tim Pease <[email protected]>
Co-authored-by: Yossef Mendelssohn <[email protected]>
Co-authored-by: Zack Koppert <[email protected]>
Co-authored-by: Zhongying Qiao <[email protected]>
Copy link
Member

@matthewd matthewd left a comment

Choose a reason for hiding this comment

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

🚀 🙌🏻

We can DRY some of the code up between Trilogy and the existing Mysql2 adapter, but I'm proposing we copy everything verbatim for now to ensure full test coverage, and clean things up in a subsequent PR.

👍🏻

@eileencodes eileencodes merged commit f7a4022 into rails:main Apr 17, 2023
@eileencodes eileencodes deleted the ac-trilogy-adapter branch April 17, 2023 18:57
eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 18, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.

The build is scoped to Rails 7.1 and above since we will not support
Trilogy for older versions of Rails.
eileencodes added a commit to rails/buildkite-config that referenced this pull request Apr 18, 2023
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.

The build is scoped to Rails 7.1 and above since we will not support
Trilogy for older versions of Rails.
rmehner added a commit to rmehner/dockerfile-rails that referenced this pull request Jun 22, 2023
…ngly

Trilogy has been in production use for quite some time and will see official Rails
support soon: rails/rails#47880

This makes sure we detect the usage of trilogy and adapt the output accordingly. We also
skip installing the libmysql-dev headers, since they're not needed with trilogy.
@ardecvz ardecvz mentioned this pull request Sep 27, 2023
3 tasks
atosbucket added a commit to atosbucket/rails-buildkit that referenced this pull request Mar 22, 2024
In rails/rails#47880 we're adding Trilogy as an
additional mysql client for Rails. This change adds a new build for it.

The build is scoped to Rails 7.1 and above since we will not support
Trilogy for older versions of Rails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants