houseabsolute / Pg-CLI

Mirror of Pg-CLI on urth.org
Other
0 stars 1 forks source link

cannot use pg_restore to print dump content to STDOUT #4

Open davewood opened 1 month ago

davewood commented 1 month ago

i can do this and it prints the postgres dump (-Fc) to STDOUT

pg_restore --file=- database.dump

using Pg::CLI::pg_restore behaves differently.

      my $pg_restore = Pg::CLI::pg_restore->new(
          username => $user,           
          password => $password,       
          host     => $host,           
          port     => $port,           
      );                               

      my $stderr;                      
      $pg_restore->run(                
          options  => [                
              '--file=-',              
          ],                           
          stderr   => \$stderr,        
          stdin    => $file,           
      );                               
      die "Error: $stderr" if $stderr; 
Error: Use of uninitialized value in system at /home/davewod/local/lib/perl5/IPC/Run3.pm line 406.
pg_restore: error: options -d/--dbname and -f/--file cannot be used together
pg_restore: hint: Try "pg_restore --help" for more information.

probably because of this line -> https://github.com/houseabsolute/Pg-CLI/blob/6dc0f7b733cd48eaae1d7f071c3b60fdb13d6b21/lib/Pg/CLI/pg_restore.pm#L23

davewood commented 1 month ago

this seems to work.

# Pg/CLI/pg_restore.pm
sub _run_options {            
    my $self     = shift;     
    my $database = shift;     

    return defined $database  
           ? ( '-d', $database )
           : ();
}