Skip to content

Commit

Permalink
Add --skip-lock-tables and --quick option (spatie#95)
Browse files Browse the repository at this point in the history
* Add skip-lock-tables option

* Add --quick option
  • Loading branch information
Koenzk authored and freekmurze committed Apr 17, 2019
1 parent c0eb0e1 commit 9013f2d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Databases/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class MySql extends DbDumper
/** @var bool */
protected $useSingleTransaction = false;

/** @var bool */
protected $skipLockTables = false;

/** @var bool */
protected $useQuick = false;

/** @var string */
protected $defaultCharacterSet = '';

Expand Down Expand Up @@ -97,6 +103,46 @@ public function dontUseSingleTransaction()
return $this;
}

/**
* @return $this
*/
public function skipLockTables()
{
$this->skipLockTables = true;

return $this;
}

/**
* @return $this
*/
public function dontSkipLockTables()
{
$this->skipLockTables = false;

return $this;
}

/**
* @return $this
*/
public function useQuick()
{
$this->useQuick = true;

return $this;
}

/**
* @return $this
*/
public function dontUseQuick()
{
$this->useQuick = false;

return $this;
}

/**
* @param string $characterSet
*
Expand Down Expand Up @@ -200,6 +246,14 @@ public function getDumpCommand(string $dumpFile, string $temporaryCredentialsFil
$command[] = '--single-transaction';
}

if ($this->skipLockTables) {
$command[] = '--skip-lock-tables';
}

if ($this->useQuick) {
$command[] = '--quick';
}

if ($this->socket !== '') {
$command[] = "--socket={$this->socket}";
}
Expand Down
26 changes: 26 additions & 0 deletions tests/MySqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@ public function it_can_generate_a_dump_command_using_single_transaction()
$this->assertSame('\'mysqldump\' --defaults-extra-file="credentials.txt" --skip-comments --extended-insert --single-transaction dbname > "dump.sql"', $dumpCommand);
}

/** @test */
public function it_can_generate_a_dump_command_using_skip_lock_tables()
{
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->skipLockTables()
->getDumpCommand('dump.sql', 'credentials.txt');

$this->assertSame('\'mysqldump\' --defaults-extra-file="credentials.txt" --skip-comments --extended-insert --skip-lock-tables dbname > "dump.sql"', $dumpCommand);
}

/** @test */
public function it_can_generate_a_dump_command_using_quick()
{
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->useQuick()
->getDumpCommand('dump.sql', 'credentials.txt');

$this->assertSame('\'mysqldump\' --defaults-extra-file="credentials.txt" --skip-comments --extended-insert --quick dbname > "dump.sql"', $dumpCommand);
}

/** @test */
public function it_can_generate_a_dump_command_with_a_custom_socket()
{
Expand Down

0 comments on commit 9013f2d

Please sign in to comment.