File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ Set a comma seperate list of tables NOT to export in `REMOTE_DATABASE_IGNORE_TAB
63
63
64
64
To generate a SQL with a custom file name ` REMOTE_DEFAULT_FILE_NAME `
65
65
66
+ To specify a different local database connection:
67
+ ```
68
+ LOCAL_DATABASE_CONNECTION=different_mysql_connection
69
+ ```
70
+
66
71
## Usage
67
72
68
73
To export a remote database to OVERRIDE your local database by running:
Original file line number Diff line number Diff line change 61
61
* Sets the default name for SQL file if --filename is not provided
62
62
*/
63
63
'defaultFileName ' => env ('REMOTE_DEFAULT_FILE_NAME ' , 'file.sql ' ),
64
+
65
+ /*
66
+ * Sets the target databse connection
67
+ */
68
+ 'targetConnection ' => env ('LOCAL_TARGET_CONNECTION ' , 'mysql ' ),
64
69
];
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ public function handle(): bool
35
35
$ removeFileAfterImport = config ('dbsync.removeFileAfterImport ' );
36
36
$ fileName = $ this ->option ('filename ' ) ?? config ('dbsync.defaultFileName ' );
37
37
38
+ $ targetConnection = config ('dbsync.targetConnection ' );
39
+
38
40
if (empty ($ host ) || empty ($ username ) || empty ($ database )) {
39
41
$ this ->error ('DB credentials not set, have you published the config and set ENV variables? ' );
40
42
@@ -49,15 +51,15 @@ public function handle(): bool
49
51
}
50
52
51
53
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 );
53
55
} 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 );
55
57
}
56
58
57
59
$ this ->comment (implode (PHP_EOL , $ output ));
58
60
59
61
if ($ importSqlFile === true ) {
60
- DB ::unprepared (file_get_contents (base_path ($ fileName )));
62
+ DB ::connection ( $ targetConnection )-> unprepared (file_get_contents (base_path ($ fileName )));
61
63
}
62
64
63
65
if ($ removeFileAfterImport === true ) {
You can’t perform that action at this time.
0 commit comments