Skip to content

Commit

Permalink
Deprecate ColumnDiff::$oldColumnName and ::getOldColumnName()
Browse files Browse the repository at this point in the history
The $oldColumnName property and the corresponding constructor parameter
were relevant until #220 (2.4.0)
which introduced the $fromColumn property and the corresponding
constructor parameter. Now they are redundant.

The same applies to getOldColumnName(). The $fromColumn property
contains all the properties of the old column including the name.
  • Loading branch information
morozov committed Aug 27, 2022
1 parent 45b2fb2 commit ea3dfad
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ awareness about deprecated code.

# Upgrade to 3.5

## Deprecated `ColumnDiff` APIs dedicated to the old column name.

The `$oldColumnName` property and the `getOldColumnName()` method of the `ColumnDiff` class have been deprecated.

Make sure the `$fromColumn` argument is passed to the `ColumnDiff` constructor and use the `$fromColumnName` property
instead.

## Marked schema diff constructors as internal.

The constructors of the following classes have been marked as internal:
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractSchemaManager::listTableDetails"/>
<referencedMethod name="Doctrine\DBAL\Schema\SqliteSchemaManager::listTableDetails"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\ColumnDiff::getOldColumnName"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down Expand Up @@ -443,6 +447,10 @@
TODO: remove in 4.0.0
-->
<referencedProperty name="Doctrine\DBAL\Schema\Column::$_customSchemaOptions"/>
<!--
TODO: remove in 4.0.0
-->
<referencedProperty name="Doctrine\DBAL\Schema\ColumnDiff::$oldColumnName"/>
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
Expand Down
11 changes: 9 additions & 2 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,15 @@ public function getAlterTableSQL(TableDiff $diff)
$columnArray = $column->toArray();

$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);

if ($columnDiff->fromColumn !== null) {
$oldColumn = $columnDiff->fromColumn;
} else {
$oldColumn = $columnDiff->getOldColumnName();
}

$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}

foreach ($diff->renamedColumns as $oldColumnName => $column) {
Expand Down
11 changes: 9 additions & 2 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,15 @@ public function getAlterTableSQL(TableDiff $diff)
continue;
}

$oldColumnName = $columnDiff->getOldColumnName()->getQuotedName($this);
$column = $columnDiff->column;
if ($columnDiff->fromColumn !== null) {
$oldColumn = $columnDiff->fromColumn;
} else {
$oldColumn = $columnDiff->getOldColumnName();
}

$oldColumnName = $oldColumn->getQuotedName($this);

$column = $columnDiff->column;

if (
$columnDiff->hasChanged('type')
Expand Down
8 changes: 7 additions & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,15 @@ public function getAlterTableSQL(TableDiff $diff)
$requireDropDefaultConstraint = $this->alterColumnRequiresDropDefaultConstraint($columnDiff);

if ($requireDropDefaultConstraint) {
if ($columnDiff->fromColumn !== null) {
$oldColumnName = $columnDiff->fromColumn->getName();
} else {
$oldColumnName = $columnDiff->oldColumnName;
}

$queryParts[] = $this->getAlterTableDropDefaultConstraintClause(
$diff->name,
$columnDiff->oldColumnName
$oldColumnName
);
}

Expand Down
18 changes: 15 additions & 3 deletions src/Schema/ColumnDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
*/
class ColumnDiff
{
/** @var string */
/**
* @deprecated Use {@see $fromColumn} and {@see Column::getName()} instead.
*
* @var string
*/
public $oldColumnName;

/** @var Column */
Expand Down Expand Up @@ -61,12 +65,20 @@ public function hasChanged($propertyName)
}

/**
* @deprecated Use {@see $fromColumn} instead.
*
* @return Identifier
*/
public function getOldColumnName()
{
$quote = $this->fromColumn !== null && $this->fromColumn->isQuoted();
if ($this->fromColumn !== null) {
$name = $this->fromColumn->getName();
$quote = $this->fromColumn->isQuoted();
} else {
$name = $this->oldColumnName;
$quote = false;
}

return new Identifier($this->oldColumnName, $quote);
return new Identifier($name, $quote);
}
}

0 comments on commit ea3dfad

Please sign in to comment.