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

Feature: support trilogy adapter #607

Merged

Conversation

zmariscal
Copy link
Contributor

Purpose

There's a new DB adapter called trilogy and this gem should be aware of it.

Implementation

Make the gem aware of the trilogy adapter by adding the gem and subsequent requires. We need to make sure the database statements value is actually and ActiveRecord::Result and not a Trilogy::Result when the adapter is trilogy. One of the reasons we need to care about this is because Trilogy::Result doesn't have #empty? implemented.

and specify #cpk_mysql_subquery if TrilogyAdapter is defined
One thing we need to ensure overall is that and ActiveRecord::Result is returned as the guts of the gem is looking to work with that object. A Trilogy::Result was being returned as `value`and that doesn't respond to #empty?
We need to load some more files as AR isn't aware of trilogy
lib/composite_primary_keys.rb Outdated Show resolved Hide resolved
test/abstract_unit.rb Outdated Show resolved Hide resolved
@cfis
Copy link
Contributor

cfis commented Sep 19, 2023

Thanks for working on this! Had a chance to review the code, and overall looks pretty good. I did leave some comments however if you could take a look.

@cfis
Copy link
Contributor

cfis commented Sep 19, 2023

FYI I enabled all tests for this MR - right now they all fail due to requiring trilogy.

@cfis
Copy link
Contributor

cfis commented Sep 26, 2023

Progress - now tests pass again except the Trilogy ones. Looks like a problem loading trilogy:

/opt/hostedtoolcache/Ruby/3.2.2/x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': Could not load the 'trilogy' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. (LoadError)

I accidentally added it to its own github action
and we for sure need trilogy here
@zmariscal
Copy link
Contributor Author

@cfis pushed up some commit that address the #empty? call for Trilogy. I'm thinking why the Trilogy tests are failing are around how AR when initially loaded isn't aware of Trilogy and that's why we need to require them again and then load. So adding the requires and connecting via ActiveRecord::Base.extend TrilogyAdapter::Connection seems to have everything working.

Screenshot 2023-09-25 at 8 57 29 PM Screenshot 2023-09-25 at 8 57 47 PM

@cfis
Copy link
Contributor

cfis commented Sep 26, 2023

Still failing, with a slightly different error now:

database configuration specifies nonexistent trilogy adapter (ActiveRecord::AdapterNotFound)

@zmariscal
Copy link
Contributor Author

zmariscal commented Sep 26, 2023

Still failing, with a slightly different error now:

database configuration specifies nonexistent trilogy adapter (ActiveRecord::AdapterNotFound)

Sorry for the confusion. I mentioned in my previous comment that I need to ensure AR is aware of Trilogy. I didn't commit that change as I know you mentioned you wanted it removed before. I've gone ahead and added the last commit with the changes I mentioned earlier. Do you mind kick off another round of the CI?

@cfis
Copy link
Contributor

cfis commented Sep 26, 2023

And onto the next issue:

home/runner/work/composite_primary_keys/composite_primary_keys/vendor/bundle/ruby/3.1.0/gems/trilogy-2.6.0/lib/trilogy.rb:16:in `_initialize': trilogy_auth_recv: TRILOGY_UNEXPECTED_PACKET (Trilogy::QueryError)

@cfis
Copy link
Contributor

cfis commented Oct 7, 2023

Thoughts?

@zmariscal
Copy link
Contributor Author

Thoughts?

Apologies for the delay. Let me look take a look and see.

@zmariscal
Copy link
Contributor Author

zmariscal commented Oct 10, 2023

Thoughts?

@cfis I pushed a commit as this may be an issue with Github Actions. Here's a link to the issue.

I setup a docker file and docker-compose.yml and everything seems to be working. Happy to open a PR to commit those to the project if it helps debug this issue.

Comment on lines 46 to 48
mysql -h 127.0.0.1 -e "CREATE USER 'test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';" -u${{ env.MYSQL_USER }} -p${{ env.MYSQL_PASSWORD }}
mysql -h 127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;" -u${{ env.MYSQL_USER }} -p${{ env.MYSQL_PASSWORD }}
mysql -h 127.0.0.1 -e "FLUSH PRIVILEGES;" -u${{ env.MYSQL_USER }} -p${{ env.MYSQL_PASSWORD }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cfis do you know if there's a way for me to run the GitHub actions on my own fork? I'm making educated guesses at the Github action issues around these mysql commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think via the .github/workflows/trilogy.yml file. But since that is part of the PR maybe it doesn't work (might have to be merged first?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cfis I can spin up a new PR and see if merging in other components first resolve this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cfis any objections in me breaking this into two PR's?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me. Sorry this taking so long to merge. I can try and focus on it next week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First PR is here: #610

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see two more PRs after that one. The first with the trilogy guts and the second being the GitHub action. How do you feel about that?

@zmariscal zmariscal force-pushed the feature--support-trilogy-adapter branch from f74ebbc to f79e913 Compare November 3, 2023 13:38
@zmariscal
Copy link
Contributor Author

@cfis I've go ahead and removed the Github Action for now. You should be able to run the docker compose up command and then docker compose exec app bash. You may need to do some DB setup, but ultimately once everything is hooked up correctly you should be able to execute bundle exec rake trilogy:test and get the following result.

@cfis cfis merged commit 4cc0b6d into composite-primary-keys:master Nov 4, 2023
16 checks passed
@cfis
Copy link
Contributor

cfis commented Nov 4, 2023

Sorry for the delay on this and thanks for keeping at it!

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.

3 participants