Skip to content

Commit

Permalink
Address deprecation of SchemaDiff::toSql()
Browse files Browse the repository at this point in the history
The new method AbstractPlatform::getAlterSchemaSQL() should be preferred
when available.
  • Loading branch information
greg0ire committed Oct 23, 2022
1 parent f33919d commit ac94d82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit ac94d82

Please sign in to comment.