Skip to content

Commit

Permalink
Remove AbstractAsset::getQuotedName()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 28, 2024
1 parent 5b1b344 commit 0567fb6
Show file tree
Hide file tree
Showing 28 changed files with 198 additions and 168 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ awareness about deprecated code.

# Upgrade to 5.0

## BC BREAK: Removed `AbstractAsset::getQuotedName()`

The `AbstractAsset::getQuotedName()` method has been removed.

## BC BREAK: Removed `AbstractAsset` namespace-related methods and property

The following namespace-related methods and property have been removed:
Expand Down
20 changes: 10 additions & 10 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ public function getAlterTableSQL(TableDiff $diff): array
]);

$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL(
$column->getQuotedName($this),
$column->getObjectName()->toSQL($this),
$columnProperties,
);
}

foreach ($diff->getDroppedColumns() as $column) {
$queryParts[] = 'DROP ' . $column->getQuotedName($this);
$queryParts[] = 'DROP ' . $column->getObjectName()->toSQL($this);
}

foreach ($diff->getChangedColumns() as $columnDiff) {
Expand All @@ -352,8 +352,8 @@ public function getAlterTableSQL(TableDiff $diff): array

$oldColumn = $columnDiff->getOldColumn();

$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumnProperties);
$queryParts[] = 'CHANGE ' . $oldColumn->getObjectName()->toSQL($this) . ' '
. $this->getColumnDeclarationSQL($newColumn->getObjectName()->toSQL($this), $newColumnProperties);
}

$addedIndexes = $this->indexAssetsByLowerCaseName($diff->getAddedIndexes());
Expand Down Expand Up @@ -400,7 +400,7 @@ public function getAlterTableSQL(TableDiff $diff): array
$tableSql = [];

if (count($queryParts) > 0) {
$tableSql[] = 'ALTER TABLE ' . $diff->getOldTable()->getQuotedName($this) . ' '
$tableSql[] = 'ALTER TABLE ' . $diff->getOldTable()->getObjectName()->toSQL($this) . ' '
. implode(', ', $queryParts);
}

Expand All @@ -418,7 +418,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];

$tableNameSQL = $diff->getOldTable()->getQuotedName($this);
$tableNameSQL = $diff->getOldTable()->getObjectName()->toSQL($this);

foreach ($diff->getModifiedIndexes() as $changedIndex) {
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $changedIndex));
Expand Down Expand Up @@ -476,7 +476,7 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde

$sql = [];

$tableNameSQL = $table->getQuotedName($this);
$tableNameSQL = $table->getObjectName()->toSQL($this);

// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach ($index->getColumns() as $columnName) {
Expand All @@ -493,7 +493,7 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde
$column->setAutoincrement(false);

$sql[] = 'ALTER TABLE ' . $tableNameSQL . ' MODIFY ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$this->getColumnDeclarationSQL($column->getObjectName()->toSQL($this), $column->toArray());

// original autoincrement information might be needed later on by other parts of the table alteration
$column->setAutoincrement(true);
Expand Down Expand Up @@ -535,7 +535,7 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff): array

$sql = [];

$tableNameSQL = $table->getQuotedName($this);
$tableNameSQL = $table->getObjectName()->toSQL($this);

foreach ($diff->getModifiedIndexes() as $changedIndex) {
// Changed primary key
Expand All @@ -554,7 +554,7 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff): array
$column->setAutoincrement(false);

$sql[] = 'ALTER TABLE ' . $tableNameSQL . ' MODIFY ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$this->getColumnDeclarationSQL($column->getObjectName()->toSQL($this), $column->toArray());

// Restore the autoincrement attribute as it might be needed later on
// by other parts of the table alteration.
Expand Down
71 changes: 44 additions & 27 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Exception\UnspecifiedConstraintName;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
Expand Down Expand Up @@ -801,7 +803,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr
throw NoColumnsSpecifiedForTable::new($table->getName());
}

$tableName = $table->getQuotedName($this);
$tableName = $table->getObjectName()->toSQL($this);
$options = $table->getOptions();
$options['uniqueConstraints'] = [];
$options['indexes'] = [];
Expand Down Expand Up @@ -856,7 +858,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr
continue;
}

$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getQuotedName($this), $comment);
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getObjectName()->toSQL($this), $comment);
}
}

Expand All @@ -880,7 +882,7 @@ public function getCreateTablesSQL(array $tables): array
foreach ($table->getForeignKeys() as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL(
$foreignKey,
$table->getQuotedName($this),
$table->getObjectName()->toSQL($this),
);
}
}
Expand All @@ -900,14 +902,14 @@ public function getDropTablesSQL(array $tables): array
foreach ($tables as $table) {
foreach ($table->getForeignKeys() as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL(
$foreignKey->getQuotedName($this),
$table->getQuotedName($this),
$this->getConstraintName($foreignKey)->toSQL($this),
$table->getObjectName()->toSQL($this),
);
}
}

foreach ($tables as $table) {
$sql[] = $this->getDropTableSQL($table->getQuotedName($this));
$sql[] = $this->getDropTableSQL($table->getObjectName()->toSQL($this));
}

return $sql;
Expand All @@ -919,7 +921,7 @@ protected function getCommentOnTableSQL(string $tableName, string $comment): str

return sprintf(
'COMMENT ON TABLE %s IS %s',
$tableName->getQuotedName($this),
$tableName->getObjectName()->toSQL($this),
$this->quoteStringLiteral($comment),
);
}
Expand All @@ -931,8 +933,8 @@ protected function getCommentOnColumnSQL(string $tableName, string $columnName,

return sprintf(
'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this),
$columnName->getQuotedName($this),
$tableName->getObjectName()->toSQL($this),
$columnName->getObjectName()->toSQL($this),
$this->quoteStringLiteral($comment),
);
}
Expand Down Expand Up @@ -1023,7 +1025,7 @@ public function getAlterSchemaSQL(SchemaDiff $diff): array
}

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

Check warning on line 1028 in src/Platforms/AbstractPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractPlatform.php#L1028

Added line #L1028 was not covered by tests
}

foreach ($diff->getCreatedSequences() as $sequence) {
Expand Down Expand Up @@ -1081,7 +1083,7 @@ public function getDropSequenceSQL(string $name): string
*/
public function getCreateIndexSQL(Index $index, string $table): string
{
$name = $index->getQuotedName($this);
$name = $index->getObjectName()->toSQL($this);
$columns = $index->getColumns();

if (count($columns) === 0) {
Expand Down Expand Up @@ -1149,8 +1151,9 @@ public function getCreateUniqueConstraintSQL(UniqueConstraint $constraint, strin
{
$sql = 'ALTER TABLE ' . $tableName . ' ADD';

if ($constraint->getName() !== '') {
$sql .= ' CONSTRAINT ' . $constraint->getQuotedName($this);
$name = $constraint->getObjectName();
if ($name !== null) {
$sql .= ' CONSTRAINT ' . $name->toSQL($this);
}

return $sql . ' UNIQUE (' . implode(', ', $constraint->getQuotedColumns($this)) . ')';
Expand Down Expand Up @@ -1204,24 +1207,24 @@ public function getRenameTableSQL(string $oldName, string $newName): string
/** @return list<string> */
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
$tableNameSQL = $diff->getOldTable()->getQuotedName($this);
$tableNameSQL = $diff->getOldTable()->getObjectName()->toSQL($this);

$sql = [];

foreach ($diff->getDroppedForeignKeys() as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableNameSQL);
$sql[] = $this->getDropForeignKeySQL($this->getConstraintName($foreignKey)->toSQL($this), $tableNameSQL);
}

foreach ($diff->getModifiedForeignKeys() as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableNameSQL);
$sql[] = $this->getDropForeignKeySQL($this->getConstraintName($foreignKey)->toSQL($this), $tableNameSQL);

Check warning on line 1219 in src/Platforms/AbstractPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractPlatform.php#L1219

Added line #L1219 was not covered by tests
}

foreach ($diff->getDroppedIndexes() as $index) {
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableNameSQL);
$sql[] = $this->getDropIndexSQL($index->getObjectName()->toSQL($this), $tableNameSQL);
}

foreach ($diff->getModifiedIndexes() as $index) {
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableNameSQL);
$sql[] = $this->getDropIndexSQL($index->getObjectName()->toSQL($this), $tableNameSQL);
}

return $sql;
Expand All @@ -1232,7 +1235,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];

$tableNameSQL = $diff->getOldTable()->getQuotedName($this);
$tableNameSQL = $diff->getOldTable()->getObjectName()->toSQL($this);

foreach ($diff->getAddedForeignKeys() as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableNameSQL);
Expand All @@ -1254,7 +1257,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
$oldIndexName = new Identifier($oldIndexName);
$sql = array_merge(
$sql,
$this->getRenameIndexSQL($oldIndexName->getQuotedName($this), $index, $tableNameSQL),
$this->getRenameIndexSQL($oldIndexName->getObjectName()->toSQL($this), $index, $tableNameSQL),
);
}

Expand Down Expand Up @@ -1498,9 +1501,10 @@ public function getUniqueConstraintDeclarationSQL(UniqueConstraint $constraint):

$chunks = [];

if ($constraint->getName() !== '') {
$name = $constraint->getObjectName();
if ($name !== null) {
$chunks[] = 'CONSTRAINT';
$chunks[] = $constraint->getQuotedName($this);
$chunks[] = $name->toSQL($this);
}

$chunks[] = 'UNIQUE';
Expand Down Expand Up @@ -1530,7 +1534,7 @@ protected function getIndexDeclarationSQL(Index $index): string
throw new InvalidArgumentException('Incomplete definition. "columns" required.');
}

return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $index->getQuotedName($this)
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $index->getObjectName()->toSQL($this)
. ' (' . implode(', ', $index->getQuotedColumns($this)) . ')' . $this->getPartialIndexSQL($index);
}

Expand Down Expand Up @@ -1602,9 +1606,11 @@ protected function getForeignKeyReferentialActionSQL(string $action): string
*/
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey): string
{
$name = $foreignKey->getObjectName();

$sql = '';
if ($foreignKey->getName() !== '') {
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
if ($name !== null) {
$sql .= 'CONSTRAINT ' . $name->toSQL($this) . ' ';
}

$sql .= 'FOREIGN KEY (';
Expand Down Expand Up @@ -2059,7 +2065,7 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s
{
$tableIdentifier = new Identifier($tableName);

return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this);
return 'TRUNCATE ' . $tableIdentifier->getObjectName()->toSQL($this);
}

/**
Expand Down Expand Up @@ -2137,7 +2143,7 @@ final public function escapeStringForLike(string $inputString, string $escapeCha
private function columnToArray(Column $column): array
{
return array_merge($column->toArray(), [
'name' => $column->getQuotedName($this),
'name' => $column->getObjectName()->toSQL($this),
'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false,
'comment' => $column->getComment(),
]);
Expand Down Expand Up @@ -2222,4 +2228,15 @@ public function normalizeUnquotedIdentifier(string $identifier): string
* database schema according to the dialect of the platform.
*/
abstract public function createSchemaManager(Connection $connection): AbstractSchemaManager;

private function getConstraintName(ForeignKeyConstraint $constraint): UnqualifiedName
{
$name = $constraint->getObjectName();

if ($name === null) {
throw UnspecifiedConstraintName::new();

Check warning on line 2237 in src/Platforms/AbstractPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractPlatform.php#L2237

Added line #L2237 was not covered by tests
}

return $name;
}
}
Loading

0 comments on commit 0567fb6

Please sign in to comment.