Skip to content

Commit 23d676f

Browse files
committed
do not call isPrimary() with DBAL 4.3, check for PrimaryKeyConstraint instead
1 parent 0b373f6 commit 23d676f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Diff for: src/Mapping/Driver/DatabaseDriver.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Schema\AbstractSchemaManager;
88
use Doctrine\DBAL\Schema\Column;
9+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
910
use Doctrine\DBAL\Schema\SchemaException;
1011
use Doctrine\DBAL\Schema\Table;
1112
use Doctrine\DBAL\Types\Type;
@@ -305,7 +306,7 @@ private function buildIndexes(ClassMetadata $metadata): void
305306
$indexes = $this->tables[$tableName]->getIndexes();
306307

307308
foreach ($indexes as $index) {
308-
if ($index->isPrimary()) {
309+
if ($index instanceof PrimaryKeyConstraint || $index->isPrimary()) {
309310
continue;
310311
}
311312

Diff for: src/Tools/SchemaTool.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,13 @@ public function getSchemaFromMetadata(array $classes): Schema
319319
$primaryKey = $table->getIndex('primary');
320320

321321
foreach ($table->getIndexes() as $idxKey => $existingIndex) {
322-
if (! $existingIndex->isPrimary() && $primaryKey->spansColumns($existingIndex->getColumns())) {
322+
if (class_exists(PrimaryKeyConstraint::class)) {
323+
$existingIndexIsPrimaryKeyConstraint = $existingIndex instanceof PrimaryKeyConstraint;
324+
} else {
325+
$existingIndexIsPrimaryKeyConstraint = $existingIndex->isPrimary();
326+
}
327+
328+
if (! $existingIndexIsPrimaryKeyConstraint && $primaryKey->spansColumns($existingIndex->getColumns())) {
323329
$table->dropIndex($idxKey);
324330
}
325331
}

Diff for: tests/Tests/ORM/Tools/SchemaToolTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Tests\ORM\Tools;
66

77
use Doctrine\Common\Collections\Collection;
8+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
89
use Doctrine\ORM\Mapping\ClassMetadata;
910
use Doctrine\ORM\Mapping\Column;
1011
use Doctrine\ORM\Mapping\Entity;
@@ -42,6 +43,7 @@
4243
use Doctrine\Tests\OrmTestCase;
4344
use PHPUnit\Framework\Attributes\Group;
4445

46+
use function class_exists;
4547
use function count;
4648
use function current;
4749

@@ -232,7 +234,12 @@ public function testRemoveUniqueIndexOverruledByPrimaryKey(): void
232234
$indexes = $schema->getTable('first_entity')->getIndexes();
233235

234236
self::assertCount(1, $indexes, 'there should be only one index');
235-
self::assertTrue(current($indexes)->isPrimary(), 'index should be primary');
237+
238+
if (class_exists(PrimaryKeyConstraint::class)) {
239+
self::assertInstanceOf(PrimaryKeyConstraint::class, current($indexes), 'index should be primary');
240+
} else {
241+
self::assertTrue(current($indexes)->isPrimary(), 'index should be primary');
242+
}
236243
}
237244

238245
public function testSetDiscriminatorColumnWithoutLength(): void

0 commit comments

Comments
 (0)