-
Notifications
You must be signed in to change notification settings - Fork 136
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
Pass all PG settings as env vars #990
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,18 +56,24 @@ def reset_candlepin | |
empty_db_in_postgresql('candlepin') | ||
end | ||
|
||
def pg_command_base(config, command, args) | ||
"PGPASSWORD='#{config[:password]}' #{command} -U #{config[:username]} -h #{config[:host]} -p #{config[:port]} #{args}" | ||
def pg_env(config) | ||
{ | ||
'PGHOST' => config.fetch(:host, 'localhost'), | ||
'PGPORT' => config.fetch(:port, '5432').to_s, | ||
'PGUSER' => config[:username], | ||
'PGPASSWORD' => config[:password], | ||
'PGDATABASE' => config[:database], | ||
} | ||
end | ||
|
||
def pg_sql_statement(config, statement) | ||
pg_command_base(config, 'psql', "-d #{config[:database]} -t -c \"#{statement}\"") | ||
def pg_sql_statement(statement) | ||
"psql -t -c \"#{statement}\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be tempted to pass in the statement via stdin but wonder if that works well with runuser (if we do that) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. runuser is only used for local sql, and there we don't need statements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that said, our |
||
end | ||
|
||
# WARNING: deletes all the data owned by the user. No warnings. No confirmations. | ||
def empty_database!(config) | ||
delete_statement = 'DROP OWNED BY CURRENT_USER CASCADE;' | ||
execute!(pg_sql_statement(config, delete_statement), false, true) | ||
execute!(pg_sql_statement(delete_statement), false, true, pg_env(config)) | ||
end | ||
|
||
def clear_pulpcore_content(content_dir) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,12 +70,12 @@ | |
|
||
it 'runs postgresql-setup --upgrade' do | ||
expect(subject).to be_nil | ||
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true) | ||
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true, {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
it 'runs vacuumdb --all --analyze-in-stages' do | ||
expect(subject).to be_nil | ||
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'vacuumdb --all --analyze-in-stages'", false, true) | ||
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'vacuumdb --all --analyze-in-stages'", false, true, {}) | ||
end | ||
end | ||
end |
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.
Do we need a default or can we trust psql to figure it out?
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.
No idea, copied from your fm patch ;)
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 I had it because
local?
compares tolocalhost
and I didn't want to change that. Perhaps we should make it more robust so it can parse any postgresql url. I'd like to be able to use unix sockets and ident auth but now we'd break foreman-maintainThere 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.
Here we have
remote_host?(hostname)
which does something very similar.The old code just assumed
config[:host]
is set (the command would be wrong if it were unset), which we can do here too?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 think keeping a default for localhost is OK for now then.