From 97487cf60719664b3f3c6fa6d5f01779ec4fdcd9 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Fri, 18 Oct 2024 13:47:16 +0200 Subject: [PATCH] Refs #37940 - pass all PostgreSQL settings as environment variables --- hooks/pre/10-reset_data.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hooks/pre/10-reset_data.rb b/hooks/pre/10-reset_data.rb index 3e6e8c22..bb3db431 100644 --- a/hooks/pre/10-reset_data.rb +++ b/hooks/pre/10-reset_data.rb @@ -56,22 +56,24 @@ def reset_candlepin empty_db_in_postgresql('candlepin') end -def pg_command_base(config, command, args) - "#{command} -U #{config[:username]} -h #{config[:host]} -p #{config[:port]} #{args}" -end - def pg_env(config) - { 'PGPASSWORD' => config[:password] } + { + '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}\"" 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, pg_env(config)) + execute!(pg_sql_statement(delete_statement), false, true, pg_env(config)) end def clear_pulpcore_content(content_dir)