@@ -42,7 +42,8 @@ def configuration
4242 end
4343
4444 def local? ( config = configuration )
45- [ 'localhost' , '127.0.0.1' , `hostname` . strip ] . include? ( config [ 'host' ] )
45+ [ 'localhost' , '127.0.0.1' , `hostname` . strip ] . include? ( config [ 'host' ] ) ||
46+ config [ 'host' ] . nil?
4647 end
4748
4849 def query ( sql , config = configuration )
@@ -57,7 +58,8 @@ def psql(query, config = configuration)
5758 if ping ( config )
5859 execute ( psql_command ( config ) ,
5960 :stdin => query ,
60- :hidden_patterns => [ config [ 'password' ] ] )
61+ :hidden_patterns => [ config [ 'password' ] ] ,
62+ :config => user )
6163 else
6264 raise_service_error
6365 end
@@ -66,11 +68,12 @@ def psql(query, config = configuration)
6668 def ping ( config = configuration )
6769 execute? ( psql_command ( config ) ,
6870 :stdin => 'SELECT 1 as ping' ,
69- :hidden_patterns => [ config [ 'password' ] ] )
71+ :hidden_patterns => [ config [ 'password' ] ] ,
72+ :user => config [ 'user' ] )
7073 end
7174
7275 def dump_db ( file , config = configuration )
73- execute! ( dump_command ( config ) + " > #{ file } " , :hidden_patterns => [ config [ 'password' ] ] )
76+ execute! ( dump_command ( config ) + " > #{ file } " , :hidden_patterns => [ config [ 'password' ] ] , :user => config [ 'user' ] )
7477 end
7578
7679 def restore_dump ( file , localdb , config = configuration )
@@ -80,11 +83,16 @@ def restore_dump(file, localdb, config = configuration)
8083 else
8184 # TODO: figure out how to completely ignore errors. Currently this
8285 # sometimes exits with 1 even though errors are ignored by pg_restore
83- dump_cmd = base_command ( config , 'pg_restore' ) +
84- ' --no-privileges --clean --disable-triggers -n public ' \
85- "-d #{ config [ 'database' ] } #{ file } "
86+ dump_cmd = ''
87+ if config [ 'connection_string' ]
88+ dump_cmd = "pg_restore --no-privileges --clean --disable-triggers -n public -d #{ config [ 'database' ] } #{ file } "
89+ else
90+ dump_cmd = base_command ( config , 'pg_restore' ) +
91+ ' --no-privileges --clean --disable-triggers -n public ' \
92+ "-d #{ config [ 'database' ] } #{ file } "
93+ end
8694 execute! ( dump_cmd , :hidden_patterns => [ config [ 'password' ] ] ,
87- :valid_exit_statuses => [ 0 , 1 ] )
95+ :valid_exit_statuses => [ 0 , 1 ] , :user => config [ 'user' ] )
8896 end
8997 end
9098
@@ -152,11 +160,19 @@ def base_command(config, command = 'psql')
152160 end
153161
154162 def psql_command ( config )
155- base_command ( config , 'psql' ) + " -d #{ config [ 'database' ] } "
163+ if config [ 'connection_string' ]
164+ "psql #{ config [ 'connection_string' ] } "
165+ else
166+ base_command ( config , 'psql' ) + " -d #{ config [ 'database' ] } "
167+ end
156168 end
157169
158170 def dump_command ( config )
159- base_command ( config , 'pg_dump' ) + " -Fc #{ config [ 'database' ] } "
171+ if config [ 'connection_string' ]
172+ "pg_dump -Fc #{ config [ 'connection_string' ] } "
173+ else
174+ base_command ( config , 'pg_dump' ) + " -Fc #{ config [ 'database' ] } "
175+ end
160176 end
161177
162178 def raise_service_error
0 commit comments