From ac94d826dcfabe729bcdde8d98e5a36977c3259a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 18 Oct 2022 22:25:49 +0200 Subject: [PATCH] Address deprecation of SchemaDiff::toSql() The new method AbstractPlatform::getAlterSchemaSQL() should be preferred when available. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 6 +++++- .../Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 3a40e9d2013..08a998a2025 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -959,7 +959,11 @@ public function getUpdateSchemaSql(array $classes, $saveMode = false) return $schemaDiff->toSaveSql($this->platform); } - return $schemaDiff->toSql($this->platform); + if (! method_exists(AbstractPlatform::class, 'getAlterSchemaSQL')) { + return $schemaDiff->toSql($this->platform); + } + + return $this->platform->getAlterSchemaSQL($schemaDiff); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 42f14669ae6..2e674d38d63 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Comparator; @@ -82,7 +83,10 @@ public function assertCreatedSchemaNeedsNoUpdates(string ...$classes): void $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema); - $sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform()); + $sql = method_exists(AbstractPlatform::class, 'getAlterSchemaSQL') ? + $this->_em->getConnection()->getDatabasePlatform()->getAlterSchemaSQL($schemaDiff) : + $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform()); + $sql = array_filter($sql, static function ($sql) { return ! str_contains($sql, 'DROP'); });