@@ -24,19 +24,35 @@ public function getImportCommand(string $dumpFile, string $connection): string
2424 $ dumper = DbDumperFactory::createFromConnection ($ connection );
2525 $ dumper ->getContentsOfCredentialsFile ();
2626
27+ $ username = config ("database.connections. {$ connection }.username " );
28+ $ password = config ("database.connections. {$ connection }.password " );
29+ $ host = config ("database.connections. {$ connection }.host " );
30+ $ port = config ("database.connections. {$ connection }.port " );
31+ $ database = config ("database.connections. {$ connection }.database " );
2732 if (str ($ dumpFile )->endsWith ('sql ' )) {
2833 return collect ([
2934 $ this ->dumpBinaryPath .'psql ' ,
3035 'postgresql:// ' .
31- urldecode (config ( " database.connections. { $ connection } . username" ) ).': ' .
32- urlencode (config ( " database.connections. { $ connection } . password" ) ).'@ ' .
33- config ( " database.connections. { $ connection } . host" ) .': ' .
34- config ( " database.connections. { $ connection } . port" ) .'/ ' .
35- config ( " database.connections. { $ connection } . database" ) ,
36+ urldecode ($ username ).': ' .
37+ urlencode ($ password ).'@ ' .
38+ $ host .': ' .
39+ $ port .'/ ' .
40+ $ database ,
3641 '< ' .$ dumpFile ,
3742 ])->implode (' ' );
3843 }
3944
45+ if ($ this ->isBinaryDump ($ dumpFile )) {
46+ return sprintf (
47+ 'pg_restore --verbose --no-owner --host=%s --port=%s --username=%s --dbname=%s %s ' ,
48+ escapeshellarg ($ host ),
49+ escapeshellarg ($ port ),
50+ escapeshellarg ($ username ),
51+ escapeshellarg ($ database ),
52+ escapeshellarg ($ dumpFile )
53+ );
54+ }
55+
4056 // @todo: Improve detection of compressed files
4157 $ decompressCommand = match (File::extension ($ dumpFile )) {
4258 'gz ' => "gunzip -c {$ dumpFile }" ,
@@ -49,16 +65,23 @@ public function getImportCommand(string $dumpFile, string $connection): string
4965 '| ' ,
5066 $ this ->dumpBinaryPath .'psql ' ,
5167 'postgresql:// ' .
52- urldecode (config ( " database.connections. { $ connection } . username" ) ).': ' .
53- urldecode (config ( " database.connections. { $ connection } . password" ) ).'@ ' .
54- config ( " database.connections. { $ connection } . host" ) .': ' .
55- config ( " database.connections. { $ connection } . port" ) .'/ ' .
56- config ( " database.connections. { $ connection } . database" ) ,
68+ urldecode ($ username ).': ' .
69+ urldecode ($ password ).'@ ' .
70+ $ host .': ' .
71+ $ port .'/ ' .
72+ $ database ,
5773 ])->implode (' ' );
5874 }
5975
6076 public function getCliName (): string
6177 {
6278 return 'psql ' ;
6379 }
80+
81+ public function isBinaryDump (string $ dumpFile ): bool
82+ {
83+ return str ($ dumpFile )->endsWith ([
84+ '.backup ' ,
85+ ]);
86+ }
6487}
0 commit comments