Skip to content

Commit 29f4e59

Browse files
Add Support to pass MySQL Options to mysql binary (#98)
1 parent 1501a99 commit 29f4e59

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

src/Databases/MySql.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function getImportCommand(string $dumpFile, string $connection): string
3131
];
3232

3333
if (str($dumpFile)->endsWith('sql')) {
34-
$command = $this->getMySqlImportCommandForUncompressedDump($importToDatabase, $dumpFile, $credentialsArray);
34+
$command = $this->getMySqlImportCommandForUncompressedDump($importToDatabase, $dumpFile, $credentialsArray, $connection);
3535
} else {
36-
$command = $this->getMySqlImportCommandForCompressedDump($dumpFile, $importToDatabase, $credentialsArray);
36+
$command = $this->getMySqlImportCommandForCompressedDump($dumpFile, $importToDatabase, $credentialsArray, $connection);
3737
}
3838

3939
return $command;
@@ -47,7 +47,7 @@ public function getCliName(): string
4747
/**
4848
* @throws ImportFailed
4949
*/
50-
private function getMySqlImportCommandForCompressedDump(string $storagePathToDatabaseFile, string $importToDatabase, array $credentials): string
50+
private function getMySqlImportCommandForCompressedDump(string $storagePathToDatabaseFile, string $importToDatabase, array $credentials, string $connection): string
5151
{
5252
$quote = $this->determineQuote();
5353
$password = $credentials['password'];
@@ -67,10 +67,11 @@ private function getMySqlImportCommandForCompressedDump(string $storagePathToDat
6767
'-P', $credentials['port'],
6868
isset($credentials['host']) ? '-h '.$credentials['host'] : '',
6969
$importToDatabase,
70+
$this->getOptions($connection),
7071
])->filter()->implode(' ');
7172
}
7273

73-
private function getMySqlImportCommandForUncompressedDump(string $importToDatabase, string $storagePathToDatabaseFile, array $credentials): string
74+
private function getMySqlImportCommandForUncompressedDump(string $importToDatabase, string $storagePathToDatabaseFile, array $credentials, string $connection): string
7475
{
7576
$quote = $this->determineQuote();
7677
$password = $credentials['password'];
@@ -82,8 +83,14 @@ private function getMySqlImportCommandForUncompressedDump(string $importToDataba
8283
'-P', $credentials['port'],
8384
isset($credentials['host']) ? '-h '.$credentials['host'] : '',
8485
$importToDatabase,
86+
$this->getOptions($connection),
8587
'<',
8688
$storagePathToDatabaseFile,
8789
])->filter()->implode(' ');
8890
}
91+
92+
private function getOptions(string $connection): string
93+
{
94+
return config("database.connections.{$connection}.dump.options", '');
95+
}
8996
}

src/Events/DatabaseDumpImportWasSuccessful.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
class DatabaseDumpImportWasSuccessful
88
{
9-
public function __construct(readonly public string $absolutePathToDump) {}
9+
public function __construct(public readonly string $absolutePathToDump) {}
1010
}

src/Events/DatabaseReset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
class DatabaseReset
1010
{
11-
public function __construct(readonly public PendingRestore $pendingRestore) {}
11+
public function __construct(public readonly PendingRestore $pendingRestore) {}
1212
}

src/Events/DatabaseRestored.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
class DatabaseRestored
1010
{
11-
public function __construct(readonly public PendingRestore $pendingRestore) {}
11+
public function __construct(public readonly PendingRestore $pendingRestore) {}
1212
}

src/HealthChecks/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Result
1010
{
1111
public function __construct(
12-
readonly public HealthCheck $healthCheck,
12+
public readonly HealthCheck $healthCheck,
1313
public int $status,
1414
public ?string $message,
1515
) {

src/PendingRestore.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
class PendingRestore
1313
{
1414
public function __construct(
15-
readonly public string $disk,
16-
readonly public string $backup,
17-
readonly public string $connection,
18-
readonly public string $restoreId,
19-
readonly public string $restoreName,
20-
#[SensitiveParameter] readonly public ?string $backupPassword = null,
21-
readonly public string $restoreDisk = 'local',
15+
public readonly string $disk,
16+
public readonly string $backup,
17+
public readonly string $connection,
18+
public readonly string $restoreId,
19+
public readonly string $restoreName,
20+
#[SensitiveParameter] public readonly ?string $backupPassword = null,
21+
public readonly string $restoreDisk = 'local',
2222
) {
2323
//
2424
}

tests/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ protected function defineEnvironment($app)
3636
'database' => env('MYSQL_DATABASE', 'laravel_backup_restore'),
3737
'username' => env('MYSQL_USERNAME', 'root'),
3838
'password' => env('MYSQL_PASSWORD', ''),
39+
'dump' => [
40+
'skip_ssl' => true,
41+
],
3942
]);
4043

4144
$app['config']->set('database.connections.mysql-restore', [

0 commit comments

Comments
 (0)