Hijack only higher-level active record adapter methods #213
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.
Every time there's a new Rails release, active record internals are refactored which, inadvertently, breaks the intended behaviour for this gem.
I've had to fix it multiple times (#201, #84, #79, #41 – that one was a patch which is supposed to be non-breaking) and, at this point, I'm just done. I don't want to fix the same issue, over and over again, every time they release a new version.
On top of that, it looks like they intend to deprecate many of these internal methods we hijack to favour the higher-level ones, and I think that makes total sense.
The higher level methods have been mostly stable since Rails 5.1. When new changes are added, they are usually backwards compatible.
With that in mind, I'm changing how we hijack the adapter methods.
exec_insertinsertinternal_exec_queryselectexec_queryexecuteexec_updateupdateexec_deletedeleteexec_queryandexecutedo not have higher-level counterparts, as they're meant to be used directly, so they will still be hijacked. I'm also addingexec_insert_allto the list, it's an exception to the rule. It doesn't have a higher-level counterpart, but also, it's not meant to be used directly. Instead it is called byInsertAll.executewhenModel.insert!is called.All the higher-level counterparts are stable API and are compatible with both raw SQL strings and Arel trees. That also gives us the chance to leverage a custom Arel parser to simplifly the AST when pattern matching read replica queries.
I'm also removing all the multiple tests for each hijackable method, since they test the exact same thing. Instead, I'll be adding new integration tests for the active record model API in #208 (i.e.
Model.all | create | first,model.save | update | destroy, etc). Those will help us detect breaking changes more easily. The current test suite is not able to find those automatically and yields false positives.