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 support for renaming tables via TableDiff #5677

Merged
merged 1 commit into from
Sep 19, 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
5 changes: 4 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ the name of the object as a separate parameter. The name of the passed index or
The `AbstractPlatform::canEmulateSchemas()` method and the schema emulation implemented in the SQLite platform
have been removed.

## BC BREAK: removed support for renaming tables via `TableDiff` and `AbstractPlatform::alterTable()`.

The `TableDiff::$newName` property and the `TableDiff::getNewName()` method have been removed.

## BC BREAK: removed `SchemaDiff` reference to the original schema.

The `SchemaDiff` class no longer accepts or exposes a reference to the original schema.
Expand Down Expand Up @@ -645,7 +649,6 @@ Table columns are no longer indexed by column name. Use the `name` attribute of
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance.
- Method `Doctrine\DBAL\Schema\Comparator::diffTable()` now optionally returns null instead of false.
- Property `Doctrine\DBAL\Schema\Table::$_primaryKeyName` is now optionally null instead of false.
- Property `Doctrine\DBAL\Schema\TableDiff::$newName` is now optionally null instead of false.
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::tablesExist()` no longer accepts a string. Use `Doctrine\DBAL\Schema\AbstractSchemaManager::tableExists()` instead.
- Method `Doctrine\DBAL\Schema\OracleSchemaManager::createDatabase()` no longer accepts `null` for `$database` argument.

Expand Down
12 changes: 0 additions & 12 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@
See https://github.com/doctrine/dbal/pull/4317
-->
<file name="tests/Functional/LegacyAPITest.php"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\TableDiff::getNewName"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedProperty name="Doctrine\DBAL\Schema\TableDiff::$newName"/>
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!--
Expand Down
12 changes: 0 additions & 12 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function array_unique;
Expand Down Expand Up @@ -311,17 +310,6 @@ public function getAlterTableSQL(TableDiff $diff): array
{
$columnSql = [];
$queryParts = [];
$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of SQL that renames a table using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);
$queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this);
}

foreach ($diff->addedColumns as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
Expand Down
9 changes: 2 additions & 7 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1422,14 +1422,9 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
/** @return string[] */
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];
$newName = $diff->getNewName();
$sql = [];

if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
}
$tableName = $diff->getName($this)->getQuotedName($this);

foreach ($diff->addedForeignKeys as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
Expand Down
20 changes: 1 addition & 19 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function count;
Expand Down Expand Up @@ -347,27 +346,10 @@ public function getAlterTableSQL(TableDiff $diff): array
$sql[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " . $diff->getName($this)->getQuotedName($this) . "')";
}

$sql = array_merge($sql, $commentsSQL);

$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of "rename table" SQL using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);
$sql[] = sprintf(
'RENAME TABLE %s TO %s',
$diff->getName($this)->getQuotedName($this),
$newName->getQuotedName($this),
);
}

$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$commentsSQL,
$this->getPostAlterTableIndexForeignKeySQL($diff),
);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Platforms/MariaDBPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,9 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
/** @return list<string> */
private function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];
$newName = $diff->getNewName();
$sql = [];

if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
}
$tableName = $diff->getName($this)->getQuotedName($this);

foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) {
if (in_array($foreignKey, $diff->changedForeignKeys, true)) {
Expand Down
20 changes: 1 addition & 19 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;

use function array_merge;
Expand Down Expand Up @@ -621,27 +620,10 @@ public function getAlterTableSQL(TableDiff $diff): array
$tableSql = [];

if (! $this->onSchemaAlterTable($diff, $tableSql)) {
$sql = array_merge($sql, $commentsSQL);

$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of "rename table" SQL using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
$newName->getQuotedName($this),
);
}

$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$commentsSQL,
$this->getPostAlterTableIndexForeignKeySQL($diff),
);
}
Expand Down
20 changes: 1 addition & 19 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;
use UnexpectedValueException;

use function array_merge;
Expand Down Expand Up @@ -342,27 +341,10 @@ public function getAlterTableSQL(TableDiff $diff): array
$tableSql = [];

if (! $this->onSchemaAlterTable($diff, $tableSql)) {
$sql = array_merge($sql, $commentsSQL);

$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of "rename table" SQL using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
$newName->getQuotedName($this),
);
}

$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$commentsSQL,
$this->getPostAlterTableIndexForeignKeySQL($diff),
);
}
Expand Down
17 changes: 1 addition & 16 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;

use function array_merge;
Expand Down Expand Up @@ -484,24 +483,10 @@ public function getAlterTableSQL(TableDiff $diff): array
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
}

$sql = array_merge($sql, $commentsSql);

$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of "rename table" SQL using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);

$sql = array_merge($sql, $this->getRenameTableSQL($diff->name, $newName->getName()));
}

$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$commentsSql,
$this->getPostAlterTableIndexForeignKeySQL($diff),
);

Expand Down
40 changes: 3 additions & 37 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\Deprecations\Deprecation;

use function array_combine;
use function array_keys;
Expand Down Expand Up @@ -485,12 +484,9 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
);
}

$sql = [];
$tableName = $diff->getNewName();
$sql = [];

if ($tableName === null) {
$tableName = $diff->getName($this);
}
$tableName = $diff->getName($this);

foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) {
if ($index->isPrimary()) {
Expand Down Expand Up @@ -689,22 +685,6 @@ public function getAlterTableSQL(TableDiff $diff): array
);
$sql[] = $this->getDropTableSQL($dataTable->getQuotedName($this));

$newName = $diff->getNewName();

if ($newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of "rename table" SQL using %s is deprecated. Use getRenameTableSQL() instead.',
__METHOD__,
);
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$newTable->getQuotedName($this),
$newName->getQuotedName($this),
);
}

$sql = array_merge($sql, $this->getPostAlterTableIndexForeignKeySQL($diff));
}

Expand Down Expand Up @@ -816,21 +796,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff): array|false
. $this->getColumnDeclarationSQL($definition['name'], $definition);
}

if (! $this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'Generation of SQL that renames a table using %s is deprecated.'
. ' Use getRenameTableSQL() instead.',
__METHOD__,
);
$newTable = new Identifier($diff->newName);

$sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO '
. $newTable->getQuotedName($this);
}
}
$this->onSchemaAlterTable($diff, $tableSql);

return array_merge($sql, $tableSql, $columnSql);
}
Expand Down
23 changes: 0 additions & 23 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
namespace Doctrine\DBAL\Schema;

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

/**
* Table Diff.
*/
class TableDiff
{
/** @deprecated Rename tables via {@link AbstractSchemaManager::renameTable()} instead. */
public ?string $newName = null;

/**
* Columns that are only renamed from key to column instance name.
*
Expand Down Expand Up @@ -81,23 +77,4 @@ public function getName(AbstractPlatform $platform): Identifier
$this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name,
);
}

/**
* @deprecated Rename tables via {@link AbstractSchemaManager::renameTable()} instead.
*/
public function getNewName(): ?Identifier
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5663',
'%s is deprecated. Rename tables via AbstractSchemaManager::renameTable() instead.',
__METHOD__,
);

if ($this->newName === null) {
return null;
}

return new Identifier($this->newName);
}
}
6 changes: 3 additions & 3 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ protected function getQuotesTableIdentifiersInAlterTableSQL(): array
return [
'ALTER TABLE `foo` DROP FOREIGN KEY fk1',
'ALTER TABLE `foo` DROP FOREIGN KEY fk2',
'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' .
'ALTER TABLE `foo` ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' .
'CHANGE id war INT NOT NULL',
'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
'ALTER TABLE `foo` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE `foo` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
];
}

Expand Down
1 change: 0 additions & 1 deletion tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,6 @@ public function testQuotesTableIdentifiersInAlterTableSQL(): void

$tableDiff = new TableDiff('"foo"');
$tableDiff->fromTable = $table;
$tableDiff->newName = 'table';
$tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer'));
$tableDiff->changedColumns['bar'] = new ColumnDiff(
new Column('bar', Type::getType('integer'), ['notnull' => false]),
Expand Down
5 changes: 2 additions & 3 deletions tests/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@ protected function getQuotesTableIdentifiersInAlterTableSQL(): array
'ALTER COLUMN bar DROP NOT NULL ' .
'RENAME COLUMN id TO war',
'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE "foo"\')',
'RENAME TABLE "foo" TO "table"',
'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
'ALTER TABLE "foo" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE "foo" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
];
}

Expand Down
Loading