Skip to content

Commit ea3dfad

Browse files
committed
Deprecate ColumnDiff::$oldColumnName and ::getOldColumnName()
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.
1 parent 45b2fb2 commit ea3dfad

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ awareness about deprecated code.
88

99
# Upgrade to 3.5
1010

11+
## Deprecated `ColumnDiff` APIs dedicated to the old column name.
12+
13+
The `$oldColumnName` property and the `getOldColumnName()` method of the `ColumnDiff` class have been deprecated.
14+
15+
Make sure the `$fromColumn` argument is passed to the `ColumnDiff` constructor and use the `$fromColumnName` property
16+
instead.
17+
1118
## Marked schema diff constructors as internal.
1219

1320
The constructors of the following classes have been marked as internal:

psalm.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@
414414
-->
415415
<referencedMethod name="Doctrine\DBAL\Schema\AbstractSchemaManager::listTableDetails"/>
416416
<referencedMethod name="Doctrine\DBAL\Schema\SqliteSchemaManager::listTableDetails"/>
417+
<!--
418+
TODO: remove in 4.0.0
419+
-->
420+
<referencedMethod name="Doctrine\DBAL\Schema\ColumnDiff::getOldColumnName"/>
417421
</errorLevel>
418422
</DeprecatedMethod>
419423
<DeprecatedProperty>
@@ -443,6 +447,10 @@
443447
TODO: remove in 4.0.0
444448
-->
445449
<referencedProperty name="Doctrine\DBAL\Schema\Column::$_customSchemaOptions"/>
450+
<!--
451+
TODO: remove in 4.0.0
452+
-->
453+
<referencedProperty name="Doctrine\DBAL\Schema\ColumnDiff::$oldColumnName"/>
446454
</errorLevel>
447455
</DeprecatedProperty>
448456
<DocblockTypeContradiction>

src/Platforms/AbstractMySQLPlatform.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,15 @@ public function getAlterTableSQL(TableDiff $diff)
642642
$columnArray = $column->toArray();
643643

644644
$columnArray['comment'] = $this->getColumnComment($column);
645-
$queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' '
646-
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
645+
646+
if ($columnDiff->fromColumn !== null) {
647+
$oldColumn = $columnDiff->fromColumn;
648+
} else {
649+
$oldColumn = $columnDiff->getOldColumnName();
650+
}
651+
652+
$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' '
653+
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
647654
}
648655

649656
foreach ($diff->renamedColumns as $oldColumnName => $column) {

src/Platforms/PostgreSQLPlatform.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,15 @@ public function getAlterTableSQL(TableDiff $diff)
561561
continue;
562562
}
563563

564-
$oldColumnName = $columnDiff->getOldColumnName()->getQuotedName($this);
565-
$column = $columnDiff->column;
564+
if ($columnDiff->fromColumn !== null) {
565+
$oldColumn = $columnDiff->fromColumn;
566+
} else {
567+
$oldColumn = $columnDiff->getOldColumnName();
568+
}
569+
570+
$oldColumnName = $oldColumn->getQuotedName($this);
571+
572+
$column = $columnDiff->column;
566573

567574
if (
568575
$columnDiff->hasChanged('type')

src/Platforms/SQLServerPlatform.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,15 @@ public function getAlterTableSQL(TableDiff $diff)
590590
$requireDropDefaultConstraint = $this->alterColumnRequiresDropDefaultConstraint($columnDiff);
591591

592592
if ($requireDropDefaultConstraint) {
593+
if ($columnDiff->fromColumn !== null) {
594+
$oldColumnName = $columnDiff->fromColumn->getName();
595+
} else {
596+
$oldColumnName = $columnDiff->oldColumnName;
597+
}
598+
593599
$queryParts[] = $this->getAlterTableDropDefaultConstraintClause(
594600
$diff->name,
595-
$columnDiff->oldColumnName
601+
$oldColumnName
596602
);
597603
}
598604

src/Schema/ColumnDiff.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
*/
1212
class ColumnDiff
1313
{
14-
/** @var string */
14+
/**
15+
* @deprecated Use {@see $fromColumn} and {@see Column::getName()} instead.
16+
*
17+
* @var string
18+
*/
1519
public $oldColumnName;
1620

1721
/** @var Column */
@@ -61,12 +65,20 @@ public function hasChanged($propertyName)
6165
}
6266

6367
/**
68+
* @deprecated Use {@see $fromColumn} instead.
69+
*
6470
* @return Identifier
6571
*/
6672
public function getOldColumnName()
6773
{
68-
$quote = $this->fromColumn !== null && $this->fromColumn->isQuoted();
74+
if ($this->fromColumn !== null) {
75+
$name = $this->fromColumn->getName();
76+
$quote = $this->fromColumn->isQuoted();
77+
} else {
78+
$name = $this->oldColumnName;
79+
$quote = false;
80+
}
6981

70-
return new Identifier($this->oldColumnName, $quote);
82+
return new Identifier($name, $quote);
7183
}
7284
}

0 commit comments

Comments
 (0)