Skip to content

Commit

Permalink
Make SQL definer replacement optional
Browse files Browse the repository at this point in the history
  • Loading branch information
p-makowski committed Nov 22, 2023
1 parent b5b9c6c commit b2c4c35
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/N98/Magento/Command/Database/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ protected function configure()
InputOption::VALUE_NONE,
'Keeps the Column Statistics table in SQL dump'
)
->addOption(
'keep-definer',
null,
InputOption::VALUE_NONE,
'Do not remove DEFINER from dump'
)
->setDescription('Dumps database with mysqldump cli client');

$help = <<<HELP
Expand Down Expand Up @@ -336,7 +342,7 @@ private function createExecs(InputInterface $input, OutputInterface $output)
// dump structure for strip-tables
$execs->add(
'--no-data ' . $mysqlClientToolConnectionString .
' ' . implode(' ', $stripTables) . $this->postDumpPipeCommands()
' ' . implode(' ', $stripTables) . $this->postDumpPipeCommands($input)
);
}

Expand All @@ -346,7 +352,12 @@ private function createExecs(InputInterface $input, OutputInterface $output)
$ignore .= '--ignore-table=' . $this->dbSettings['dbname'] . '.' . $ignoreTable . ' ';
}

$execs->add($ignore . $mysqlClientToolConnectionString . $postDumpGitFriendlyPipeCommands . $this->postDumpPipeCommands());
$execs->add(
$ignore
. $mysqlClientToolConnectionString
. $postDumpGitFriendlyPipeCommands
. $this->postDumpPipeCommands($input)
);

return $execs;
}
Expand Down Expand Up @@ -491,12 +502,15 @@ private function resolveDatabaseTables($list)
/**
* Commands which filter mysql data. Piped to mysqldump command
*
* @param InputInterface $input
* @return string
*/
protected function postDumpPipeCommands()
protected function postDumpPipeCommands(InputInterface $input)
{
return ' | LANG=C LC_CTYPE=C LC_ALL=C sed -E '
. escapeshellarg('s/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g');
return $input->getOption('keep-definer')
? ''
: ' | LANG=C LC_CTYPE=C LC_ALL=C sed -E '
. escapeshellarg('s/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g');
}

/**
Expand Down

0 comments on commit b2c4c35

Please sign in to comment.