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

Add deprecation layer for TableDiff methods #6482

Merged
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: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 4.1

## Deprecated `TableDiff` methods

The `TableDiff` methods `getModifiedColumns()` and `getRenamedColumns()` have been merged into a single
method `getChangedColumns()`. Use this method instead.

## Deprecated support for MariaDB 10.4 and MySQL 5.7

* Upgrade to MariaDB 10.5 or later.
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
See https://github.com/doctrine/dbal/pull/6202
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\TableDiff::getModifiedColumns" />
<referencedMethod name="Doctrine\DBAL\Schema\TableDiff::getRenamedColumns" />
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getColumnTypeSQLSnippets" />
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getDatabaseNameSQL" />

Expand Down
49 changes: 49 additions & 0 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace Doctrine\DBAL\Schema;

use Doctrine\Deprecations\Deprecation;

use function array_filter;
use function array_values;
use function count;

/**
Expand Down Expand Up @@ -60,6 +63,52 @@ public function getChangedColumns(): array
return $this->changedColumns;
}

/**
* @deprecated Use {@see getChangedColumns()} instead.
*
* @return list<ColumnDiff>
*/
public function getModifiedColumns(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6280',
'%s is deprecated, use `getChangedColumns()` instead.',
__METHOD__,
);

return array_values(array_filter(
$this->getChangedColumns(),
static fn (ColumnDiff $diff): bool => $diff->countChangedProperties() > ($diff->hasNameChanged() ? 1 : 0),
));
}

/**
* @deprecated Use {@see getChangedColumns()} instead.
*
* @return array<string,Column>
*/
public function getRenamedColumns(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6280',
'%s is deprecated, you should use `getChangedColumns()` instead.',
__METHOD__,
);
$renamed = [];
foreach ($this->getChangedColumns() as $diff) {
if (! $diff->hasNameChanged()) {
continue;
}

$oldColumnName = $diff->getOldColumn()->getName();
$renamed[$oldColumnName] = $diff->getNewColumn();
}

return $renamed;
}

/** @return array<Column> */
public function getDroppedColumns(): array
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/Platform/RenameColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function testColumnPositionRetainedAfterImplicitRenaming(string $columnNa
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
self::assertCount(1, self::getRenamedColumns($diff));
self::assertCount(1, $diff->getRenamedColumns());
}

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

self::assertCount(1, $diff->getChangedColumns());
self::assertCount(1, $diff->getRenamedColumns());
self::assertCount(1, $diff->getModifiedColumns());
self::assertCount(2, $columns);
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public function testRenameColumnComparison(): void

$compareResult = $comparator->compareTables($onlineTable, $table);
$renamedColumns = RenameColumnTest::getRenamedColumns($compareResult);
self::assertSame($renamedColumns, $compareResult->getRenamedColumns());
self::assertCount(3, $compareResult->getChangedColumns());
self::assertCount(2, $compareResult->getModifiedColumns());
self::assertCount(2, $renamedColumns);
self::assertArrayHasKey('test2', $renamedColumns);

Expand Down
Loading