Skip to content

Commit 4657fa3

Browse files
committed
Remove configuration for reporting modified indexes
1 parent 6d493f6 commit 4657fa3

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

UPGRADE.md

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

99
# Upgrade to 5.0
1010

11+
## Deprecated `ComparatorConfig::withReportModifiedIndexes()`
12+
1113
## BC BREAK: Changes in features related to primary key constraints
1214

1315
1. The `Index` class can no longer represent a primary key constraint. As a result:
@@ -38,6 +40,10 @@ The following auto-increment column definitions are no longer supported on SQLit
3840

3941
The `TableDiff::getModifiedForeignKeys()` and `TableDiff::getModifiedIndexes()` methods have been removed.
4042

43+
The comparator can be no longer configured to report modified indexes. The
44+
`ComparatorConfig::withReportModifiedIndexes()` only accepts `false` as the argument and has been deprecated. The
45+
`ComparatorConfig::getReportModifiedIndexes()` method has been removed.
46+
4147
## BC BREAK: changes in `AbstractPlatform` constructor
4248

4349
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/XXXX',
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc
159159
)
160160
->create(),
161161
);
162-
}, (new ComparatorConfig())->withReportModifiedIndexes(false));
162+
});
163163
}
164164

165165
public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn(): void
@@ -193,7 +193,7 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn
193193
)
194194
->create(),
195195
);
196-
}, (new ComparatorConfig())->withReportModifiedIndexes(false));
196+
});
197197
}
198198

199199
public function testAddNewColumnToPrimaryKey(): void
@@ -270,7 +270,7 @@ public function testReplaceForeignKeyConstraint(): void
270270
});
271271
}
272272

273-
private function testMigration(Table $oldTable, callable $migration, ?ComparatorConfig $config = null): void
273+
private function testMigration(Table $oldTable, callable $migration): void
274274
{
275275
$this->dropAndCreateTable($oldTable);
276276

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

282282
$migration($newTable);
283283

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

287287
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/XXXX');
25+
(new ComparatorConfig())->withReportModifiedIndexes(false);
26+
}
27+
}

0 commit comments

Comments
 (0)