Skip to content

Commit

Permalink
feat: 🎉 Add Feature to Skip AUTO_INCREMENT Values in MySQL Dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonymiler committed Mar 31, 2024
1 parent bdc6b2a commit 1c6d79d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Databases/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MySql extends DbDumper

protected string $setGtidPurged = 'AUTO';

protected bool $skipAutoIncrement = false;

protected bool $createTables = true;

/** @var false|resource */
Expand Down Expand Up @@ -129,6 +131,18 @@ public function setGtidPurged(string $setGtidPurged): self
return $this;
}

public function skipAutoIncrement(): self
{
$this->skipAutoIncrement = true;
return $this;
}

public function dontSkipAutoIncrement(): self
{
$this->skipAutoIncrement = false;
return $this;
}

public function dumpToFile(string $dumpFile): void
{
$this->guardAgainstIncompleteCredentials();
Expand Down Expand Up @@ -233,7 +247,15 @@ public function getDumpCommand(string $dumpFile, string $temporaryCredentialsFil
$command[] = $extraOptionAfterDbName;
}

return $this->echoToFile(implode(' ', $command), $dumpFile);
$finalDumpCommand = implode(' ', $command);

if ($this->skipAutoIncrement) {
$sedCommand = "sed 's/ AUTO_INCREMENT=[0-9]*\b//'";
$finalDumpCommand .= " | {$sedCommand}";
}

return $this->echoToFile($finalDumpCommand, $dumpFile);

}

public function getContentsOfCredentialsFile(): string
Expand Down

0 comments on commit 1c6d79d

Please sign in to comment.