Skip to content

Commit

Permalink
Remove backward-compatibility layer
Browse files Browse the repository at this point in the history
Note that we also remove UpdateCommandTest::testItPrintsTheSql() because
it relied on not passing --complete to work.
  • Loading branch information
greg0ire committed Jun 5, 2023
1 parent f389229 commit 0945f60
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function configure(): void
$this->setName($this->name)
->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
->addOption('complete', null, InputOption::VALUE_NONE, 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.')
->addOption('complete', null, InputOption::VALUE_NONE, 'This option is a no-op and will be removed in 4.0')
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Dumps the generated SQL statements to the screen (does not execute them).')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Causes the generated SQL statements to be physically executed against your database.')
->setHelp(<<<'EOT'
Expand All @@ -50,11 +50,10 @@ protected function configure(): void
<info>%command.name% --dump-sql --force</info>
Finally, be aware that if the <info>--complete</info> option is passed, this
task will drop all database assets (e.g. tables, etc) that are *not* described
by the current metadata. In other words, without this option, this task leaves
untouched any "extra" tables that exist in the database, but which aren't
described by any metadata. Not passing that option is deprecated.
Finally, be aware that this task will drop all database assets (e.g. tables,
etc) that are *not* described by the current metadata. In other words, without
this option, this task leaves untouched any "extra" tables that exist in the
database, but which aren't described by any metadata.
<comment>Hint:</comment> If you have a database with tables that should not be managed
by the ORM, you can use a DBAL functionality to filter the tables and sequences down
Expand All @@ -71,17 +70,7 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
{
$notificationUi = $ui->getErrorStyle();

// Defining if update is complete or not (--complete not defined means $saveMode = true)
$saveMode = ! $input->getOption('complete');

if ($saveMode) {
$notificationUi->warning(sprintf(
'Not passing the "--complete" option to "%s" is deprecated and will not be supported when using doctrine/dbal 4',
$this->getName() ?? $this->name,
));
}

$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
$sqls = $schemaTool->getUpdateSchemaSql($metadatas);

if (empty($sqls)) {
$notificationUi->success('Nothing to update - your database is already in sync with the current entity metadata.');
Expand All @@ -106,7 +95,7 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
$notificationUi->text('Updating database schema...');
$notificationUi->newLine();

$schemaTool->updateSchema($metadatas, $saveMode);
$schemaTool->updateSchema($metadatas);

$pluralization = count($sqls) === 1 ? 'query was' : 'queries were';

Expand Down
39 changes: 5 additions & 34 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand All @@ -37,7 +36,6 @@
use function class_exists;
use function count;
use function current;
use function func_num_args;
use function implode;
use function in_array;
use function is_numeric;
Expand Down Expand Up @@ -885,24 +883,12 @@ public function getDropSchemaSQL(array $classes): array
* instances to the current database schema that is inspected.
*
* @param mixed[] $classes
* @param bool $saveMode If TRUE, only performs a partial update
* without dropping assets which are scheduled for deletion.
*/
public function updateSchema(array $classes, bool $saveMode = false): void
public function updateSchema(array $classes): void
{
if (func_num_args() > 1) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10153',
'Passing $saveMode to %s() is deprecated and will not be possible in Doctrine ORM 3.0.',
__METHOD__,
);
}
$conn = $this->em->getConnection();

$updateSchemaSql = $this->getUpdateSchemaSql($classes, $saveMode);
$conn = $this->em->getConnection();

foreach ($updateSchemaSql as $sql) {
foreach ($this->getUpdateSchemaSql($classes) as $sql) {
$conn->executeStatement($sql);
}
}
Expand All @@ -911,32 +897,17 @@ public function updateSchema(array $classes, bool $saveMode = false): void
* Gets the sequence of SQL statements that need to be performed in order
* to bring the given class mappings in-synch with the relational schema.
*
* @param bool $saveMode If TRUE, only generates SQL for a partial update
* that does not include SQL for dropping assets which are scheduled for deletion.
* @param list<ClassMetadata> $classes The classes to consider.
* @param list<ClassMetadata> $classes The classes to consider.
*
* @return list<string> The sequence of SQL statements.
*/
public function getUpdateSchemaSql(array $classes, bool $saveMode = false): array
public function getUpdateSchemaSql(array $classes): array
{
if (func_num_args() > 1) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10153',
'Passing $saveMode to %s() is deprecated and will not be possible in Doctrine ORM 3.0.',
__METHOD__,
);
}

$toSchema = $this->getSchemaFromMetadata($classes);
$fromSchema = $this->createSchemaForComparison($toSchema);
$comparator = $this->schemaManager->createComparator();
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

if ($saveMode) {
return $schemaDiff->toSaveSql($this->platform);
}

return $this->platform->getAlterSchemaSQL($schemaDiff);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ public function getUpdateSchemaList(): array

$allMetadata = $this->em->getMetadataFactory()->getAllMetadata();

return $schemaTool->getUpdateSchemaSql($allMetadata, true);
return $schemaTool->getUpdateSchemaSql($allMetadata);
}
}
6 changes: 0 additions & 6 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ parameters:
-
message: '~Strict comparison using \=\=\= between callable\(\)\: mixed and null will always evaluate to false\.~'
path: lib/Doctrine/ORM/Tools/SchemaTool.php

# FIXME
-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Schema\\\\SchemaDiff\\:\\:toSaveSql\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/SchemaTool.php
2 changes: 0 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
<!-- Compatibility with DBAL 3 -->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Schema\Schema::visit"/>
<!-- Remove on 3.0.x -->
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSaveSql"/>
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down

This file was deleted.

0 comments on commit 0945f60

Please sign in to comment.