10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/run_psql.rb', line 10
def run_pg_command(config, command, output_file=nil)
database = config["database"]
username = config["username"]
host = config["host"]
port = config["port"]
password = config["password"]
pipe_to_file = output_file ? "> #{output_file}" : ""
variables = "-v ON_ERROR_STOP=1"
puts "Executing: #{command} -U #{username} #{host ? '-h '+host : ''} #{port ? '-p '+port.to_s : ''} #{database} #{pipe_to_file}"
`export PGPASSWORD="#{password}"`
`#{command} #{variables} -U #{username} #{host ? '-h '+host : ''} #{port ? '-p '+port.to_s : ''} #{database} #{pipe_to_file}`
exit_status = $?.exitstatus
`export PGPASSWORD=""`
puts "exit status: #{exit_status}"
if exit_status != 0
raise "pg command failed"
end
end
|