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

Fixes #23704 - allow subnet order by network #5623

Merged
merged 1 commit into from
Mar 4, 2020

Conversation

ares
Copy link
Member

@ares ares commented May 30, 2018

No description provided.

@theforeman-bot
Copy link
Member

Issues: #23704

lzap
lzap previously approved these changes May 30, 2018
Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Nicely done, I like ignoring it for sqlite, that's sane approach. Small nitpick: I'd probably prefer using context in the test to prevent future copy-and-paste.

@ares
Copy link
Member Author

ares commented May 30, 2018

repushed with the context that deduplicates subnets setup, @lzap mind to take another look?

lzap
lzap previously approved these changes May 30, 2018
Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

WFM

@@ -34,4 +34,19 @@ def subnet_params_filter
def subnet_params
self.class.subnet_params_filter.filter_params(params, parameter_filter_context)
end

def network_reorder(base)
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this should actually be a Model concern.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this approach, I failed to find a way to hook into scoped search, scoped search does not provide a way to implement casting, especially not for just some adapters. Then I thought let's do it in model, but I'd need to extend Subnet::ActiveRecord_Relation, not Subnet class. And then I gave up.

Now I realize that we can actually define it in Subnet model and it works just fine. So here you are, thanks for pushing me :-)

Subnet.all.network_reorder
Subnet.all.network_reorder 'network DESC'

ekohl
ekohl previously approved these changes May 30, 2018
@mmoll
Copy link
Contributor

mmoll commented May 30, 2018

test fails 💔

app/models/subnet.rb Outdated Show resolved Hide resolved
@ares
Copy link
Member Author

ares commented Jul 10, 2018

[test foreman]

@lzap
Copy link
Member

lzap commented Jul 11, 2018

Relevant test failures.

@lzap
Copy link
Member

lzap commented Sep 19, 2019

@ares this is a nice patch, can you rebase and make tests green? Then I am good to merge.

@ares
Copy link
Member Author

ares commented Oct 4, 2019

I plan to revisit this after 1.24 branching when MySQL will be dropped.

@ares
Copy link
Member Author

ares commented Nov 20, 2019

Dropped mysql and sqlite specific code, now focusing on postgres only. Also rebased, it should be ready fo rereview

@ares
Copy link
Member Author

ares commented Nov 26, 2019

failures related

@ares
Copy link
Member Author

ares commented Dec 12, 2019

I need to add sqlite switch back to silently ignore this :-/

@ares
Copy link
Member Author

ares commented Dec 12, 2019

this should now be green on sqlite too

@ares
Copy link
Member Author

ares commented Dec 21, 2019

ready for rereview :-)

@ares
Copy link
Member Author

ares commented Jan 15, 2020

Let's get this one in, it's opened for more than 1.5 year, pretty covered with tests, easy to test. Pretty please :-)

@ares
Copy link
Member Author

ares commented Feb 17, 2020

ping @lzap

def self.network_reorder(order_string = 'network')
adapter = connection.adapter_name.downcase
if adapter.starts_with?('postgresql')
self.reorder(order_string.sub('network', 'inet(network)'))
Copy link
Member

Choose a reason for hiding this comment

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

Given we're now PostgreSQL-only, should we actually make a migration that uses the inet type for the column?

Copy link
Member Author

Choose a reason for hiding this comment

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

don't we need to still support sqlite for ci?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but you can have a conditional in the migration. You'd end up with the same difference that you have now. The only thing I'd be worried about is that it might serialize to a different object (IPAddr for example) and the code would behave differently. That's why I won't insist on it, but would ask you to consider it.

@tbrisker what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't tested myself, but found this, meaning we'd get IPAddr instance as you say. We'd need to update the method or many other places where .to_s is not called implicitly, I guess API, templates could be affected

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave that till later, but long term I think it would be a good improvement. We can even drop the separate cidr field since PostgreSQL can store it in a single field.

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

Thanks @ares !

@tbrisker tbrisker merged commit c5565a6 into theforeman:develop Mar 4, 2020
@lzap
Copy link
Member

lzap commented Mar 5, 2020

Apologies for the delay, thanks indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants