Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SchemaDiff::toSql() and SchemaDiff::toSaveSql() #5774

Merged
merged 1 commit into from
Oct 18, 2022
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
4 changes: 0 additions & 4 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSql"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\Comparator::diffTable"/>
</errorLevel>
</DeprecatedMethod>
Expand Down
40 changes: 39 additions & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,48 @@ public function getCreateTemporaryTableSnippetSQL(): string
* Generates SQL statements that can be used to apply the diff.
*
* @return list<string>
*
* @throws Exception
*/
public function getAlterSchemaSQL(SchemaDiff $diff): array
{
return $diff->toSql($this);
$sql = [];

if ($this->supportsSchemas()) {
foreach ($diff->getCreatedSchemas() as $schema) {
$sql[] = $this->getCreateSchemaSQL($schema);
}
}

if ($this->supportsSequences()) {
foreach ($diff->getAlteredSequences() as $sequence) {
$sql[] = $this->getAlterSequenceSQL($sequence);
}

foreach ($diff->getDroppedSequences() as $sequence) {
$sql[] = $this->getDropSequenceSQL($sequence->getQuotedName($this));
}

foreach ($diff->getCreatedSequences() as $sequence) {
$sql[] = $this->getCreateSequenceSQL($sequence);
}
}

$sql = array_merge(
$sql,
$this->getCreateTablesSQL(
$diff->getCreatedTables(),
),
$this->getDropTablesSQL(
$diff->getDroppedTables(),
),
);

foreach ($diff->getAlteredTables() as $tableDiff) {
$sql = array_merge($sql, $this->getAlterTableSQL($tableDiff));
}

return $sql;
}

/**
Expand Down
87 changes: 0 additions & 87 deletions src/Schema/SchemaDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\Deprecation;

use function array_filter;
use function array_merge;
use function array_values;
use function count;

/**
Expand Down Expand Up @@ -111,86 +106,4 @@ public function isEmpty(): bool
&& count($this->alteredSequences) === 0
&& count($this->droppedSequences) === 0;
}

/**
* The to save sql mode ensures that the following things don't happen:
*
* 1. Tables are deleted
* 2. Sequences are deleted
* 3. Foreign Keys which reference tables that would otherwise be deleted.
*
* This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all.
*
* @deprecated
*
* @return list<string>
*/
public function toSaveSql(AbstractPlatform $platform): array
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5766',
'%s is deprecated.',
__METHOD__,
);

return $this->_toSql($platform, true);
}

/**
* @deprecated Use {@link AbstractPlatform::getAlterSchemaSQL()} instead.
*
* @return list<string>
*/
public function toSql(AbstractPlatform $platform): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5766',
'%s is deprecated. Use AbstractPlatform::getAlterSchemaSQL() instead.',
__METHOD__,
);

return $this->_toSql($platform, false);
}

/** @return list<string> */
protected function _toSql(AbstractPlatform $platform, bool $saveMode = false): array
{
$sql = [];

if ($platform->supportsSchemas()) {
foreach ($this->getCreatedSchemas() as $schema) {
$sql[] = $platform->getCreateSchemaSQL($schema);
}
}

if ($platform->supportsSequences()) {
foreach ($this->getAlteredSequences() as $sequence) {
$sql[] = $platform->getAlterSequenceSQL($sequence);
}

if ($saveMode === false) {
foreach ($this->getDroppedSequences() as $sequence) {
$sql[] = $platform->getDropSequenceSQL($sequence->getQuotedName($platform));
}
}

foreach ($this->getCreatedSequences() as $sequence) {
$sql[] = $platform->getCreateSequenceSQL($sequence);
}
}

$sql = array_merge($sql, $platform->getCreateTablesSQL(array_values($this->getCreatedTables())));

if ($saveMode === false) {
$sql = array_merge($sql, $platform->getDropTablesSQL(array_values($this->getDroppedTables())));
}

foreach ($this->getAlteredTables() as $tableDiff) {
$sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
}

return $sql;
}
}