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

Refactor BaseDatabase class for simplicity #945

Merged
merged 14 commits into from
Oct 21, 2024

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Oct 17, 2024

This aims to make the BaseDatabase class easier to follow. At this point it's untested, but it was inspired by #939. At this point it's untested and not everything may make sense. It's structured as smaller commits that should be fairly straight forward to follow.

evgeni and others added 4 commits October 17, 2024 17:30
The configuration is an instance level setting that is never passed in.
This simplifies the code by avoiding the need to pass it around.
This avoids needing to use a shell.
@ekohl ekohl force-pushed the clean-up-base-db branch 2 times, most recently from d3d4932 to 9bed8ed Compare October 17, 2024 15:56
'PGHOST' => configuration.fetch('host', 'localhost'),
'PGPORT' => configuration.fetch('port', '5432'),
'PGUSER' => configuration.fetch('username'),
'PGPASSWORD' => configuration[%(password)],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'PGPASSWORD' => configuration[%(password)],
'PGPASSWORD' => configuration['password'],

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 kept that from the previous implementation, but I agree that if we focus on simplicity that we should also apply it here.

Copy link
Member

Choose a reason for hiding this comment

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

There it was just to escape (lol) quoting hell because of

"PGPASSWORD='#{config[%(password)]}' "

Here it's just weird :)

def base_env
{
'PGHOST' => configuration.fetch('host', 'localhost'),
'PGPORT' => configuration.fetch('port', '5432'),
Copy link
Member

@evgeni evgeni Oct 21, 2024

Choose a reason for hiding this comment

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

Suggested change
'PGPORT' => configuration.fetch('port', '5432'),
'PGPORT' => configuration.fetch('port', '5432').to_s,

the port is technically an integer, and depending on where we get it from (and how), it might actually be one, but env as received by Open3 needs to be strings only.

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 now changed it so it can be nil, but now I'm not sure Open3 accepts nil values.

Copy link
Member

Choose a reason for hiding this comment

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

nil is OK, as that means "unset"

@evgeni
Copy link
Member

evgeni commented Oct 21, 2024

I've taken this for a test-ride and it seems to behave just fine, thanks!

ekohl and others added 9 commits October 21, 2024 14:22
This avoids the need to build a complex command. On the plus side, it
avoids the risk of leaking anything about the database access. On the
downside, that can make debugging harder.
This avoids the need for another helper command and simplifies the
commands.
This matches other queries.
This uses a block that won't run if @deb_postgresql_versions is already
set.
This wasn't used in the past for Ruby 1.9 or 2.0 support, but we can now
rely on this. It makes testing easier.
@evgeni
Copy link
Member

evgeni commented Oct 21, 2024

well, you broke your own tests, but ACK once green :)

@evgeni evgeni merged commit 5d1eb19 into theforeman:master Oct 21, 2024
8 checks passed
let(:expected_env) do
{
'PGHOST' => 'localhost',
'PGPORT' => nil,
Copy link
Member Author

Choose a reason for hiding this comment

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

Just for my own sanity, I checked and https://rubyapi.org/3.3/o/process states:

Optional leading argument env is a hash of name/value pairs, where each name is a string and each value is a string or nil; each name/value pair is added to ENV in the new process.

@ekohl ekohl deleted the clean-up-base-db branch October 21, 2024 14:22
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.

2 participants