Skip to content

Commit 5a04320

Browse files
authored
Merge pull request #6898 from morozov/remove-reporting-modified-indexes
Remove configuration for reporting modified indexes
2 parents 6d493f6 + 0fd7f37 commit 5a04320

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

UPGRADE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ The following auto-increment column definitions are no longer supported on SQLit
3838

3939
The `TableDiff::getModifiedForeignKeys()` and `TableDiff::getModifiedIndexes()` methods have been removed.
4040

41+
The comparator can be no longer configured to report modified indexes.
42+
The `ComparatorConfig::withReportModifiedIndexes()` method only accepts `false` as the argument and has been deprecated.
43+
4144
## BC BREAK: changes in `AbstractPlatform` constructor
4245

4346
The `AbstractPlatform` class constructor is now `protected` and requires an `UnquotedIdentifierFolding` instance as its

src/Schema/ComparatorConfig.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7+
use Doctrine\DBAL\Exception\InvalidArgumentException;
8+
use Doctrine\Deprecations\Deprecation;
9+
710
final class ComparatorConfig
811
{
912
public function __construct(
1013
private readonly bool $detectRenamedColumns = true,
1114
private readonly bool $detectRenamedIndexes = true,
12-
private readonly bool $reportModifiedIndexes = true,
1315
) {
1416
}
1517

@@ -18,7 +20,6 @@ public function withDetectRenamedColumns(bool $detectRenamedColumns): self
1820
return new self(
1921
$detectRenamedColumns,
2022
$this->detectRenamedIndexes,
21-
$this->reportModifiedIndexes,
2223
);
2324
}
2425

@@ -32,7 +33,6 @@ public function withDetectRenamedIndexes(bool $detectRenamedIndexes): self
3233
return new self(
3334
$this->detectRenamedColumns,
3435
$detectRenamedIndexes,
35-
$this->reportModifiedIndexes,
3636
);
3737
}
3838

@@ -41,17 +41,20 @@ public function getDetectRenamedIndexes(): bool
4141
return $this->detectRenamedIndexes;
4242
}
4343

44+
/** @deprecated Reporting of modified indexes cannot be enabled anymore. */
4445
public function withReportModifiedIndexes(bool $reportModifiedIndexes): self
4546
{
46-
return new self(
47-
$this->detectRenamedColumns,
48-
$this->detectRenamedIndexes,
49-
$reportModifiedIndexes,
47+
if ($reportModifiedIndexes) {
48+
throw new InvalidArgumentException('Reporting of modified indexes cannot be enabled anymore.');
49+
}
50+
51+
Deprecation::trigger(
52+
'doctrine/dbal',
53+
'https://github.com/doctrine/dbal/pull/6898',
54+
'%s is deprecated and has no effect on the comparator behavior.',
55+
__METHOD__,
5056
);
51-
}
5257

53-
public function getReportModifiedIndexes(): bool
54-
{
55-
return $this->reportModifiedIndexes;
58+
return $this;
5659
}
5760
}

tests/Functional/Schema/AlterTableTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
88
use Doctrine\DBAL\Platforms\DB2Platform;
99
use Doctrine\DBAL\Platforms\SQLitePlatform;
10-
use Doctrine\DBAL\Schema\ComparatorConfig;
1110
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1211
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
1312
use Doctrine\DBAL\Schema\Table;
@@ -159,7 +158,7 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc
159158
)
160159
->create(),
161160
);
162-
}, (new ComparatorConfig())->withReportModifiedIndexes(false));
161+
});
163162
}
164163

165164
public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn(): void
@@ -193,7 +192,7 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn
193192
)
194193
->create(),
195194
);
196-
}, (new ComparatorConfig())->withReportModifiedIndexes(false));
195+
});
197196
}
198197

199198
public function testAddNewColumnToPrimaryKey(): void
@@ -270,7 +269,7 @@ public function testReplaceForeignKeyConstraint(): void
270269
});
271270
}
272271

273-
private function testMigration(Table $oldTable, callable $migration, ?ComparatorConfig $config = null): void
272+
private function testMigration(Table $oldTable, callable $migration): void
274273
{
275274
$this->dropAndCreateTable($oldTable);
276275

@@ -281,7 +280,7 @@ private function testMigration(Table $oldTable, callable $migration, ?Comparator
281280

282281
$migration($newTable);
283282

284-
$diff = $schemaManager->createComparator($config ?? new ComparatorConfig())
283+
$diff = $schemaManager->createComparator()
285284
->compareTables($oldTable, $newTable);
286285

287286
self::assertFalse($diff->isEmpty());

tests/Schema/ComparatorConfigTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Tests\Schema;
6+
7+
use Doctrine\DBAL\Schema\ComparatorConfig;
8+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
9+
use InvalidArgumentException;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ComparatorConfigTest extends TestCase
13+
{
14+
use VerifyDeprecations;
15+
16+
public function testEnableReportingOfModifiedIndexes(): void
17+
{
18+
$this->expectException(InvalidArgumentException::class);
19+
(new ComparatorConfig())->withReportModifiedIndexes(true);
20+
}
21+
22+
public function testDisableReportingOfModifiedIndexes(): void
23+
{
24+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/6898');
25+
(new ComparatorConfig())->withReportModifiedIndexes(false);
26+
}
27+
}

0 commit comments

Comments
 (0)