Skip to content

Commit

Permalink
update schema state
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 8, 2020
1 parent 4026844 commit d67be13
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Illuminate\Database\Schema;

use Exception;
use Illuminate\Support\Str;
use Symfony\Component\Process\Process;

class MySqlSchemaState extends SchemaState
{
/**
Expand All @@ -12,9 +16,9 @@ class MySqlSchemaState extends SchemaState
*/
public function dump($path)
{
$this->makeProcess(
$this->executeDumpProcess($this->makeProcess(
$this->baseDumpCommand().' --routines --result-file=$LARAVEL_LOAD_PATH --no-data'
)->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [
), $this->output, array_merge($this->baseVariables($this->connection->getConfig()), [
'LARAVEL_LOAD_PATH' => $path,
]));

Expand Down Expand Up @@ -46,9 +50,9 @@ protected function removeAutoIncrementingState(string $path)
*/
protected function appendMigrationData(string $path)
{
with($process = $this->makeProcess(
$process = $this->executeDumpProcess($this->makeProcess(
$this->baseDumpCommand().' migrations --no-create-info --skip-extended-insert --skip-routines --compact'
))->mustRun(null, array_merge($this->baseVariables($this->connection->getConfig()), [
), null, array_merge($this->baseVariables($this->connection->getConfig()), [
//
]));

Expand Down Expand Up @@ -98,4 +102,29 @@ protected function baseVariables(array $config)
'LARAVEL_LOAD_DATABASE' => $config['database'],
];
}

/**
* Execute the given dump process.
*
* @param \Symfony\Component\Process\Process $process
* @param callable $output
* @param array $variables
* @return \Symfony\Component\Process\Process
*/
protected function executeDumpProcess(Process $process, $output, array $variables)
{
try {
$process->mustRun($output, $variables);
} catch (Exception $e) {
if (Str::contains($e->getMessage(), 'column_statistics')) {
$process = Process::fromShellCommandLine(
str_replace(' --column-statistics=0', '', $process->getCommandLine())
);

return $this->executeDumpProcess($process, $output, $variables);
}
}

return $process;
}
}

0 comments on commit d67be13

Please sign in to comment.