Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
"slug": "4.0",
"upcoming": true
},
{
"name": "3.10",
"branchName": "3.10.x",
"slug": "3.10",
"upcoming": true
},
{
"name": "3.9",
"branchName": "3.9.x",
"slug": "3.9",
"upcoming": true
"current": true
},
{
"name": "3.8",
"branchName": "3.8.x",
"slug": "3.8",
"current": true
"maintained": false
},
{
"name": "3.7",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.2.2"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.3.0"
2 changes: 1 addition & 1 deletion .github/workflows/composer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
composer-lint:
name: "Composer Lint"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@7.2.2"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@7.3.0"
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.2.2"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.3.0"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/website-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ on:
jobs:
json-validate:
name: "Validate JSON schema"
uses: "doctrine/.github/.github/workflows/website-schema.yml@7.2.2"
uses: "doctrine/.github/.github/workflows/website-schema.yml@7.3.0"
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ parameters:
-
message: '~Doctrine\\ORM\\Tools\\Console\\Helper\\EntityManagerHelper~'
path: src/Tools/Console/ConsoleRunner.php
-
message: '#^Usage of deprecated trait Symfony\\Component\\VarExporter\\LazyProxyTrait in class Doctrine\\Migrations\\Provider\\LazySchema\:\nsince Symfony 7\.3, use native lazy objects instead$#'
path: src/Provider/LazySchema.php

symfony:
console_application_loader: tests/doctrine-migrations-phpstan-app.php
Expand Down
3 changes: 3 additions & 0 deletions src/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function generate(
string $fqcn,
string|null $filterExpression,
bool $formatted = false,
bool|null $nowdocOutput = null,
int $lineLength = 120,
bool $checkDbPlatform = true,
bool $fromEmptySchema = false,
Expand Down Expand Up @@ -83,6 +84,7 @@ static function ($assetName) use ($filterExpression) {
$up = $this->migrationSqlGenerator->generate(
$upSql,
$formatted,
$nowdocOutput,
$lineLength,
$checkDbPlatform,
);
Expand All @@ -92,6 +94,7 @@ static function ($assetName) use ($filterExpression) {
$down = $this->migrationSqlGenerator->generate(
$downSql,
$formatted,
$nowdocOutput,
$lineLength,
$checkDbPlatform,
);
Expand Down
23 changes: 13 additions & 10 deletions src/Generator/SqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use function str_repeat;
use function stripos;
use function strlen;
use function var_export;

/**
* The SqlGenerator class is responsible for generating the body of the up() and down() methods for a migration
Expand All @@ -40,12 +41,14 @@ public function __construct(
public function generate(
array $sql,
bool $formatted = false,
bool|null $nowdocOutput = null,
int $lineLength = 120,
bool $checkDbPlatform = true,
): string {
$code = [];

$storageConfiguration = $this->configuration->getMetadataStorageConfiguration();
$maxLength = $lineLength - 18 - 8; // max - php code length - indentation
foreach ($sql as $query) {
if (
$storageConfiguration instanceof TableMetadataStorageConfiguration
Expand All @@ -54,18 +57,18 @@ public function generate(
continue;
}

if ($formatted) {
$maxLength = $lineLength - 18 - 8; // max - php code length - indentation

if (strlen($query) > $maxLength) {
$query = $this->formatQuery($query);
}
if ($formatted && strlen($query) > $maxLength) {
$query = $this->formatQuery($query);
}

$code[] = sprintf(
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
preg_replace('/^/m', str_repeat(' ', 4), $query),
);
if ($nowdocOutput === true || ($nowdocOutput !== false && $formatted && strlen($query) > $maxLength )) {
$code[] = sprintf(
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
preg_replace('/^/m', str_repeat(' ', 4), $query),
);
} else {
$code[] = sprintf('$this->addSql(%s);', var_export($query, true));
}
}

if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) {
Expand Down
3 changes: 3 additions & 0 deletions src/SchemaDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function dump(
string $fqcn,
array $excludedTablesRegexes = [],
bool $formatted = false,
bool $nowdocOutput = false,
int $lineLength = 120,
): string {
$schema = $this->schemaManager->introspectSchema();
Expand All @@ -73,6 +74,7 @@ public function dump(
$upCode = $this->migrationSqlGenerator->generate(
$upSql,
$formatted,
$nowdocOutput,
$lineLength,
);

Expand All @@ -85,6 +87,7 @@ public function dump(
$downCode = $this->migrationSqlGenerator->generate(
$downSql,
$formatted,
$nowdocOutput,
$lineLength,
);

Expand Down
8 changes: 8 additions & 0 deletions src/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Format the generated SQL.',
)
->addOption(
'nowdoc',
null,
InputOption::VALUE_NEGATABLE,
'Output the generated SQL as a nowdoc string (always active for formatted queries).',
)
->addOption(
'line-length',
null,
Expand Down Expand Up @@ -102,6 +108,7 @@ protected function execute(
}

$formatted = filter_var($input->getOption('formatted'), FILTER_VALIDATE_BOOLEAN);
$nowdocOutput = filter_var($input->getOption('nowdoc'), FILTER_VALIDATE_BOOLEAN);
$lineLength = (int) $input->getOption('line-length');
$allowEmptyDiff = $input->getOption('allow-empty-diff');
$checkDbPlatform = filter_var($input->getOption('check-database-platform'), FILTER_VALIDATE_BOOLEAN);
Expand Down Expand Up @@ -135,6 +142,7 @@ protected function execute(
$fqcn,
$filterExpression,
$formatted,
$nowdocOutput,
$lineLength,
$checkDbPlatform,
$fromEmptySchema,
Expand Down
15 changes: 13 additions & 2 deletions src/Tools/Console/Command/DumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

use function addslashes;
use function class_exists;
use function filter_var;
use function sprintf;
use function str_contains;

use const FILTER_VALIDATE_BOOLEAN;

/**
* The DumpSchemaCommand class is responsible for dumping your current database schema to a migration class. This is
* intended to be used in conjunction with the RollupCommand.
Expand Down Expand Up @@ -49,6 +52,12 @@ protected function configure(): void
InputOption::VALUE_NONE,
'Format the generated SQL.',
)
->addOption(
'nowdoc',
null,
InputOption::VALUE_NONE,
'Output the generated SQL as a nowdoc string (always active for formatted queries).',
)
->addOption(
'namespace',
null,
Expand All @@ -75,8 +84,9 @@ public function execute(
InputInterface $input,
OutputInterface $output,
): int {
$formatted = $input->getOption('formatted');
$lineLength = (int) $input->getOption('line-length');
$formatted = filter_var($input->getOption('formatted'), FILTER_VALIDATE_BOOLEAN);
$nowdocOutput = filter_var($input->getOption('nowdoc'), FILTER_VALIDATE_BOOLEAN);
$lineLength = (int) $input->getOption('line-length');

$schemaDumper = $this->getDependencyFactory()->getSchemaDumper();

Expand All @@ -98,6 +108,7 @@ public function execute(
$fqcn,
$input->getOption('filter-tables'),
$formatted,
$nowdocOutput,
$lineLength,
);

Expand Down
7 changes: 4 additions & 3 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testGenerate(): void
->with(self::logicalOr(
self::equalTo(['UPDATE table SET value = 2']),
self::equalTo(['UPDATE table SET value = 1']),
), true, 80)
), true, false, 80)
->willReturnOnConsecutiveCalls('test1', 'test2');

$this->migrationGenerator->expects(self::once())
Expand All @@ -114,6 +114,7 @@ public function testGenerate(): void
'1234',
'/table_name1/',
true,
false,
80,
));
}
Expand Down Expand Up @@ -169,15 +170,15 @@ public function testGenerateFromEmptySchema(): void
->with(self::logicalOr(
self::equalTo(['CREATE TABLE table_name']),
self::equalTo(['DROP TABLE table_name']),
), false, 120, true)
), false, false, 120, true)
->willReturnOnConsecutiveCalls('test up', 'test down');

$this->migrationGenerator->expects(self::once())
->method('generateMigration')
->with('2345', 'test up', 'test down')
->willReturn('path2');

self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, false, 120, true, true));
}

protected function setUp(): void
Expand Down
Loading