Skip to content

Commit 6ef1518

Browse files
derrabusTofandel
andauthored
Add deprecation layer for TableDiff methods (#6482)
| Q | A |------------- | ----------- | Type | feature | Fixed issues | N/A #### Summary #6280 removed columns without explicitly deprecating them. This PR adds the missing deprecation layer. Co-authored-by: Tofandel <[email protected]>
1 parent 741e9fc commit 6ef1518

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

UPGRADE.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 4.1
1010

11+
## Deprecated `TableDiff` methods
12+
13+
The `TableDiff` methods `getModifiedColumns()` and `getRenamedColumns()` have been merged into a single
14+
method `getChangedColumns()`. Use this method instead.
15+
1116
## Deprecated support for MariaDB 10.4 and MySQL 5.7
1217

1318
* Upgrade to MariaDB 10.5 or later.

psalm.xml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
See https://github.com/doctrine/dbal/pull/6202
6060
TODO: remove in 4.0.0
6161
-->
62+
<referencedMethod name="Doctrine\DBAL\Schema\TableDiff::getModifiedColumns" />
63+
<referencedMethod name="Doctrine\DBAL\Schema\TableDiff::getRenamedColumns" />
6264
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getColumnTypeSQLSnippets" />
6365
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getDatabaseNameSQL" />
6466

src/Schema/TableDiff.php

+49
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7+
use Doctrine\Deprecations\Deprecation;
8+
79
use function array_filter;
10+
use function array_values;
811
use function count;
912

1013
/**
@@ -60,6 +63,52 @@ public function getChangedColumns(): array
6063
return $this->changedColumns;
6164
}
6265

66+
/**
67+
* @deprecated Use {@see getChangedColumns()} instead.
68+
*
69+
* @return list<ColumnDiff>
70+
*/
71+
public function getModifiedColumns(): array
72+
{
73+
Deprecation::triggerIfCalledFromOutside(
74+
'doctrine/dbal',
75+
'https://github.com/doctrine/dbal/pull/6280',
76+
'%s is deprecated, use `getChangedColumns()` instead.',
77+
__METHOD__,
78+
);
79+
80+
return array_values(array_filter(
81+
$this->getChangedColumns(),
82+
static fn (ColumnDiff $diff): bool => $diff->countChangedProperties() > ($diff->hasNameChanged() ? 1 : 0),
83+
));
84+
}
85+
86+
/**
87+
* @deprecated Use {@see getChangedColumns()} instead.
88+
*
89+
* @return array<string,Column>
90+
*/
91+
public function getRenamedColumns(): array
92+
{
93+
Deprecation::triggerIfCalledFromOutside(
94+
'doctrine/dbal',
95+
'https://github.com/doctrine/dbal/pull/6280',
96+
'%s is deprecated, you should use `getChangedColumns()` instead.',
97+
__METHOD__,
98+
);
99+
$renamed = [];
100+
foreach ($this->getChangedColumns() as $diff) {
101+
if (! $diff->hasNameChanged()) {
102+
continue;
103+
}
104+
105+
$oldColumnName = $diff->getOldColumn()->getName();
106+
$renamed[$oldColumnName] = $diff->getNewColumn();
107+
}
108+
109+
return $renamed;
110+
}
111+
63112
/** @return array<Column> */
64113
public function getDroppedColumns(): array
65114
{

tests/Functional/Platform/RenameColumnTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testColumnPositionRetainedAfterImplicitRenaming(string $columnNa
3939
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
4040
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
4141
self::assertCount(1, self::getRenamedColumns($diff));
42+
self::assertCount(1, $diff->getRenamedColumns());
4243
}
4344

4445
/** @return array<string,Column> */
@@ -79,6 +80,8 @@ public function testColumnPositionRetainedAfterExplicitRenaming(string $columnNa
7980
$columns = $table->getColumns();
8081

8182
self::assertCount(1, $diff->getChangedColumns());
83+
self::assertCount(1, $diff->getRenamedColumns());
84+
self::assertCount(1, $diff->getModifiedColumns());
8285
self::assertCount(2, $columns);
8386
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
8487
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());

tests/Functional/Schema/ComparatorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public function testRenameColumnComparison(): void
7474

7575
$compareResult = $comparator->compareTables($onlineTable, $table);
7676
$renamedColumns = RenameColumnTest::getRenamedColumns($compareResult);
77+
self::assertSame($renamedColumns, $compareResult->getRenamedColumns());
7778
self::assertCount(3, $compareResult->getChangedColumns());
79+
self::assertCount(2, $compareResult->getModifiedColumns());
7880
self::assertCount(2, $renamedColumns);
7981
self::assertArrayHasKey('test2', $renamedColumns);
8082

0 commit comments

Comments
 (0)