Skip to content

Commit

Permalink
Add an option for to not generate a database platform code
Browse files Browse the repository at this point in the history
Resolve doctrine#781
  • Loading branch information
roukmoute committed Jan 17, 2019
1 parent 1d6ebbf commit da223d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/Doctrine/Migrations/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function generate(
string $versionNumber,
?string $filterExpression,
bool $formatted = false,
int $lineLength = 120
int $lineLength = 120,
bool $checkDbPlatorm = true
) : string {
if ($filterExpression !== null) {
$this->dbalConfiguration->setFilterSchemaAssetsExpression($filterExpression);
Expand All @@ -76,13 +77,15 @@ public function generate(
$up = $this->migrationSqlGenerator->generate(
$fromSchema->getMigrateToSql($toSchema, $this->platform),
$formatted,
$lineLength
$lineLength,
$checkDbPlatorm
);

$down = $this->migrationSqlGenerator->generate(
$fromSchema->getMigrateFromSql($toSchema, $this->platform),
$formatted,
$lineLength
$lineLength,
$checkDbPlatorm
);

if ($up === '' && $down === '') {
Expand Down
13 changes: 12 additions & 1 deletion lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Doctrine\Migrations\Provider\OrmSchemaProvider;
use Doctrine\Migrations\Provider\SchemaProviderInterface;
use Doctrine\Migrations\Tools\Console\Exception\InvalidOptionUsage;
use const FILTER_VALIDATE_BOOLEAN;
use function filter_var;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -72,6 +74,13 @@ protected function configure() : void
InputOption::VALUE_OPTIONAL,
'Max line length of unformatted lines.',
120
)
->addOption(
'check-database-platform',
null,
InputOption::VALUE_OPTIONAL,
'Check Database Platform to the generated code.',
true
);
}

Expand All @@ -85,6 +94,7 @@ public function execute(
$filterExpression = $input->getOption('filter-expression') ?? null;
$formatted = (bool) $input->getOption('formatted');
$lineLength = (int) $input->getOption('line-length');
$checkDbPlatorm = filter_var($input->getOption('check-database-platform'), FILTER_VALIDATE_BOOLEAN);

if ($formatted) {
if (! class_exists('SqlFormatter')) {
Expand All @@ -100,7 +110,8 @@ public function execute(
$versionNumber,
$filterExpression,
$formatted,
$lineLength
$lineLength,
$checkDbPlatorm
);

$editorCommand = $input->getOption('editor-cmd');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function testExecute() : void
->willReturn(80);

$input->expects(self::at(3))
->method('getOption')
->with('check-database-platform')
->willReturn(true);

$input->expects(self::at(4))
->method('getOption')
->with('editor-cmd')
->willReturn('mate');
Expand Down

0 comments on commit da223d4

Please sign in to comment.