Skip to content

Commit adde876

Browse files
committed
Add target database connection and fix mysqldump port param
1 parent b640d7e commit adde876

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Set a comma seperate list of tables NOT to export in `REMOTE_DATABASE_IGNORE_TAB
6363

6464
To generate a SQL with a custom file name `REMOTE_DEFAULT_FILE_NAME`
6565

66+
To specify a different local database connection:
67+
```
68+
LOCAL_DATABASE_CONNECTION=different_mysql_connection
69+
```
70+
6671
## Usage
6772

6873
To export a remote database to OVERRIDE your local database by running:

config/dbsync.php

+5
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@
6161
* Sets the default name for SQL file if --filename is not provided
6262
*/
6363
'defaultFileName' => env('REMOTE_DEFAULT_FILE_NAME', 'file.sql'),
64+
65+
/*
66+
* Sets the target databse connection
67+
*/
68+
'targetConnection' => env('LOCAL_TARGET_CONNECTION', 'mysql'),
6469
];

src/Console/DbSyncCommand.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function handle(): bool
3535
$removeFileAfterImport = config('dbsync.removeFileAfterImport');
3636
$fileName = $this->option('filename') ?? config('dbsync.defaultFileName');
3737

38+
$targetConnection = config('dbsync.targetConnection');
39+
3840
if (empty($host) || empty($username) || empty($database)) {
3941
$this->error('DB credentials not set, have you published the config and set ENV variables?');
4042

@@ -49,15 +51,15 @@ public function handle(): bool
4951
}
5052

5153
if ($useSsh === true) {
52-
exec("ssh $sshUsername@$host -p$sshPort mysqldump --port$port -u$username -p$password $database $ignoreString > $fileName", $output);
54+
exec("ssh $sshUsername@$host -p$sshPort mysqldump -P$port -u$username -p$password $database $ignoreString > $fileName", $output);
5355
} else {
54-
exec("mysqldump -h$host --port$port -u$username -p$password $database $ignoreString --column-statistics=0 > $fileName", $output);
56+
exec("mysqldump -h$host -P$port -u$username -p$password $database $ignoreString --column-statistics=0 > $fileName", $output);
5557
}
5658

5759
$this->comment(implode(PHP_EOL, $output));
5860

5961
if ($importSqlFile === true) {
60-
DB::unprepared(file_get_contents(base_path($fileName)));
62+
DB::connection($targetConnection)->unprepared(file_get_contents(base_path($fileName)));
6163
}
6264

6365
if ($removeFileAfterImport === true) {

0 commit comments

Comments
 (0)