Skip to content

Commit 49a07a3

Browse files
author
hamidafghan
committed
Make file name dynamic
1 parent 54ec520 commit 49a07a3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Console/DbSyncCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function handle(): bool
3131
$ignoreTables = explode(',', $ignore);
3232
$importSqlFile = config('dbsync.importSqlFile');
3333
$removeFileAfterImport = config('dbsync.removeFileAfterImport');
34+
$fileName = $this->argument('filename') ?? config('dbsync.defaultFileName');
3435

3536
if (empty($host) || empty($username) || empty($database)) {
3637
$this->error("DB credentials not set, have you published the config and set ENV variables?");
@@ -45,19 +46,19 @@ public function handle(): bool
4546
}
4647

4748
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);
4950
} 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);
5152
}
5253

5354
$this->comment(implode(PHP_EOL, $output));
5455

5556
if ($importSqlFile === true) {
56-
DB::unprepared(file_get_contents(base_path('file.sql')));
57+
DB::unprepared(file_get_contents(base_path($fileName)));
5758
}
5859

5960
if ($removeFileAfterImport === true) {
60-
unlink('file.sql');
61+
unlink($fileName);
6162
}
6263
}
6364

0 commit comments

Comments
 (0)