File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use Doctrine \DBAL \Schema \AbstractSchemaManager ;
8
8
use Doctrine \DBAL \Schema \Column ;
9
+ use Doctrine \DBAL \Schema \PrimaryKeyConstraint ;
9
10
use Doctrine \DBAL \Schema \SchemaException ;
10
11
use Doctrine \DBAL \Schema \Table ;
11
12
use Doctrine \DBAL \Types \Type ;
@@ -305,7 +306,7 @@ private function buildIndexes(ClassMetadata $metadata): void
305
306
$ indexes = $ this ->tables [$ tableName ]->getIndexes ();
306
307
307
308
foreach ($ indexes as $ index ) {
308
- if ($ index ->isPrimary ()) {
309
+ if ($ index instanceof PrimaryKeyConstraint || $ index ->isPrimary ()) {
309
310
continue ;
310
311
}
311
312
Original file line number Diff line number Diff line change @@ -319,7 +319,13 @@ public function getSchemaFromMetadata(array $classes): Schema
319
319
$ primaryKey = $ table ->getIndex ('primary ' );
320
320
321
321
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 ())) {
323
329
$ table ->dropIndex ($ idxKey );
324
330
}
325
331
}
Original file line number Diff line number Diff line change 5
5
namespace Doctrine \Tests \ORM \Tools ;
6
6
7
7
use Doctrine \Common \Collections \Collection ;
8
+ use Doctrine \DBAL \Schema \PrimaryKeyConstraint ;
8
9
use Doctrine \ORM \Mapping \ClassMetadata ;
9
10
use Doctrine \ORM \Mapping \Column ;
10
11
use Doctrine \ORM \Mapping \Entity ;
42
43
use Doctrine \Tests \OrmTestCase ;
43
44
use PHPUnit \Framework \Attributes \Group ;
44
45
46
+ use function class_exists ;
45
47
use function count ;
46
48
use function current ;
47
49
@@ -232,7 +234,12 @@ public function testRemoveUniqueIndexOverruledByPrimaryKey(): void
232
234
$ indexes = $ schema ->getTable ('first_entity ' )->getIndexes ();
233
235
234
236
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
+ }
236
243
}
237
244
238
245
public function testSetDiscriminatorColumnWithoutLength (): void
You can’t perform that action at this time.
0 commit comments