-
Notifications
You must be signed in to change notification settings - Fork 74
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
[Bugfix][Oracle] path order in routing_policy working for null/empty values #1173
Conversation
5d4957a
to
e5257d0
Compare
Codecov Report
@@ Coverage Diff @@
## master #1173 +/- ##
==========================================
+ Coverage 92.99% 93.03% +0.04%
==========================================
Files 2454 2455 +1
Lines 80951 80986 +35
==========================================
+ Hits 75281 75348 +67
+ Misses 5670 5638 -32
Continue to review full report at Codecov.
|
e5257d0
to
003009b
Compare
003009b
to
41e3e3f
Compare
@@ -17,7 +17,7 @@ def initialize(service) | |||
end | |||
|
|||
def to_a | |||
rules = backend_api_configs.reorder(path: :desc).each_with_object([]) do |config, rules| | |||
rules = backend_api_configs.reorder('CASE WHEN path IS NULL THEN 1 ELSE 0 END, path DESC').each_with_object([]) do |config, rules| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use COALESCE
instead (with sift) and make it Oracle only just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoke with Gui, and we discovered that baby squeel does not offer reorder construct yet: rzane/baby_squeel#73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backend_api_configs.reorder('CASE WHEN path IS NULL THEN 1 ELSE 0 END, path DESC')
works for the 3 DBs, however it might be a better idea for speed in the other DBs (not sure, so share your opinions) doing the specific query of Oracle only on Oracle so the others do not execute stuff they do not need, like this:
reorder = System::Database.oracle? ? 'CASE WHEN path IS NULL THEN 1 ELSE 0 END, path DESC' : {path: :desc}
backend_api_configs.reorder(reorder)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact then i could make it oracle specific like:
reorder = System::Database.oracle? ? 'path DESC NULLS LAST' : {path: :desc}
rules = backend_api_configs.reorder(reorder).each_with_object([]) do |config, rules|
# ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say let's make it specific for Oracle. Even though it works for all supported DBs to this day, a principle applies: the fix is meant for Oracle only.
One day we may have to support some weird DB to which this fix does NOT work and neither is necessary. Another thing that could happen is – who knows? – we drop support to Oracle one day. Then we'd end up with some ugly code for DBs that do need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these are the 2 options, and both work in all DBs:
rules = backend_api_configs.reorder('CASE WHEN path IS NULL THEN 1 ELSE 0 END, path DESC').each_with_object([]) do |config, rules|
# ...
reorder = System::Database.oracle? ? 'path DESC NULLS LAST' : {path: :desc}
rules = backend_api_configs.reorder(reorder).each_with_object([]) do |config, rules|
# ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good 👍 So I will push the last once 👍 And it is also definitely more understandable at first glance 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just discovered that reordering
exists now in baby squeel 😄because i tried it locally after seeing https://www.bountysource.com/issues/53307207-reordering-without-explicit-direction-doesn-t-work-with-last-in-rails-4
So I will do the sifter 😄
7c0ba70
to
ed9fb32
Compare
ed9fb32
to
411b370
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
As a future improvement (in case we ever need it), we could make sifter :path_desc
more generic so it works with any column name and both ways :asc
and :desc
.
Test it locally with oracle DB for the test:
test/unit/proxy_test.rb:103
For Oracle the empty string is saved as
NULL
.