@@ -66,14 +66,17 @@ def psql(query, config = configuration)
6666 end
6767
6868 def ping ( config = configuration )
69- execute? ( psql_command ( config ) ,
70- :stdin => 'SELECT 1 as ping' ,
69+ execute? ( psql_command ( config ) + ' -c "SELECT 1 as ping"' ,
7170 :hidden_patterns => [ config [ 'password' ] ] ,
7271 :user => config [ 'user' ] )
7372 end
7473
7574 def dump_db ( file , config = configuration )
76- execute! ( dump_command ( config ) + " > #{ file } " , :hidden_patterns => [ config [ 'password' ] ] , :user => config [ 'user' ] )
75+ if config [ 'user' ]
76+ execute! ( "chown -R #{ config [ 'user' ] } :#{ config [ 'user' ] } #{ File . dirname ( file ) } " )
77+ end
78+ execute! ( dump_command ( config ) + " -f #{ file } " ,
79+ :hidden_patterns => [ config [ 'password' ] ] , :user => config [ 'user' ] )
7780 end
7881
7982 def restore_dump ( file , localdb , config = configuration )
@@ -83,13 +86,17 @@ def restore_dump(file, localdb, config = configuration)
8386 else
8487 # TODO: figure out how to completely ignore errors. Currently this
8588 # sometimes exits with 1 even though errors are ignored by pg_restore
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 } "
89+ base_cmd = ''
90+ base_cmd = if config [ 'connection_string' ]
91+ 'pg_restore'
92+ else
93+ base_command ( config , 'pg_restore' )
94+ end
95+ dump_cmd = base_cmd +
96+ ' --no-privileges --clean --disable-triggers -n public ' \
97+ "-d #{ config [ 'database' ] } #{ file } "
98+ if config [ 'user' ]
99+ execute! ( "chown -R #{ config [ 'user' ] } :#{ config [ 'user' ] } #{ File . dirname ( file ) } " )
93100 end
94101 execute! ( dump_cmd , :hidden_patterns => [ config [ 'password' ] ] ,
95102 :valid_exit_statuses => [ 0 , 1 ] , :user => config [ 'user' ] )
@@ -169,9 +176,9 @@ def psql_command(config)
169176
170177 def dump_command ( config )
171178 if config [ 'connection_string' ]
172- "pg_dump -Fc #{ config [ 'connection_string' ] } "
179+ "pg_dump --format=c #{ config [ 'connection_string' ] } "
173180 else
174- base_command ( config , 'pg_dump' ) + " -Fc #{ config [ 'database' ] } "
181+ base_command ( config , 'pg_dump' ) + " --format=c #{ config [ 'database' ] } "
175182 end
176183 end
177184
0 commit comments