File tree 3 files changed +15
-7
lines changed
3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,9 @@ You can publish the config file with:
23
23
24
24
```
25
25
php artisan vendor:publish --provider="Dcblogdev\DbSync\DbSyncServiceProvider" --tag="config"
26
- ```
26
+ ```
27
27
28
- ## .env
28
+ ## .env
29
29
30
30
Set the remote database credentials in your .env file
31
31
@@ -59,6 +59,8 @@ REMOTE_IMPORT_FILE=true
59
59
60
60
Set a comma seperate list of tables NOT to export in ` REMOTE_DATABASE_IGNORE_TABLES `
61
61
62
+ To generate a SQL with a custom file name ` REMOTE_DEFAULT_FILE_NAME `
63
+
62
64
## Usage
63
65
64
66
To export a remote database to OVERRIDE your local database by running:
Original file line number Diff line number Diff line change 48
48
'importSqlFile ' => env ('REMOTE_IMPORT_FILE ' , 'true ' ),
49
49
50
50
/**
51
- * Sets if the generated file.sql will be deleted after it has been imported.
51
+ * Sets if the generated SQL file will be deleted after it has been imported.
52
52
*/
53
53
'removeFileAfterImport ' => env ('REMOTE_REMOVE_FILE_AFTER_IMPORT ' , 'true ' ),
54
+
55
+ /**
56
+ * Sets the default name for SQL file if --filename is not provided
57
+ */
58
+ 'defaultFileName ' => env ('REMOTE_DEFAULT_FILE_NAME ' , 'file.sql ' ),
54
59
];
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public function handle(): bool
31
31
$ ignoreTables = explode (', ' , $ ignore );
32
32
$ importSqlFile = config ('dbsync.importSqlFile ' );
33
33
$ removeFileAfterImport = config ('dbsync.removeFileAfterImport ' );
34
+ $ fileName = $ this ->argument ('filename ' ) ?? config ('dbsync.defaultFileName ' );
34
35
35
36
if (empty ($ host ) || empty ($ username ) || empty ($ database )) {
36
37
$ this ->error ("DB credentials not set, have you published the config and set ENV variables? " );
@@ -45,19 +46,19 @@ public function handle(): bool
45
46
}
46
47
47
48
if ($ useSsh === true ) {
48
- exec ("ssh $ sshUsername@ $ host -p $ sshPort mysqldump -u $ username -p $ password $ database $ ignoreString > file.sql " , $ output );
49
+ exec ("ssh $ sshUsername@ $ host -p $ sshPort mysqldump -u $ username -p $ password $ database $ ignoreString > $ fileName " , $ output );
49
50
} else {
50
- exec ("mysqldump -h $ host -u $ username -p $ password $ database $ ignoreString --column-statistics=0 > file.sql " , $ output );
51
+ exec ("mysqldump -h $ host -u $ username -p $ password $ database $ ignoreString --column-statistics=0 > $ fileName " , $ output );
51
52
}
52
53
53
54
$ this ->comment (implode (PHP_EOL , $ output ));
54
55
55
56
if ($ importSqlFile === true ) {
56
- DB ::unprepared (file_get_contents (base_path (' file.sql ' )));
57
+ DB ::unprepared (file_get_contents (base_path ($ fileName )));
57
58
}
58
59
59
60
if ($ removeFileAfterImport === true ) {
60
- unlink (' file.sql ' );
61
+ unlink ($ fileName );
61
62
}
62
63
}
63
64
You can’t perform that action at this time.
0 commit comments