File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 2626use function array_map ;
2727use function array_merge ;
2828use function array_values ;
29+ use function assert ;
2930use function count ;
3031use function implode ;
3132use function in_array ;
@@ -200,6 +201,13 @@ public function addPrimaryKeyConstraint(PrimaryKeyConstraint $primaryKeyConstrai
200201 $ primaryKeyConstraint ->getObjectName ()?->toString(),
201202 );
202203
204+ // there is no way to set a primary index with flags. we have to set it and then add the flag
205+ if (! $ primaryKeyConstraint ->isClustered ()) {
206+ $ index = $ this ->getPrimaryKey ();
207+ assert ($ index !== null );
208+ $ index ->addFlag ('nonclustered ' );
209+ }
210+
203211 $ this ->primaryKeyConstraint = $ primaryKeyConstraint ;
204212
205213 return $ this ;
Original file line number Diff line number Diff line change 1515use Doctrine \DBAL \Schema \Comparator ;
1616use Doctrine \DBAL \Schema \ComparatorConfig ;
1717use Doctrine \DBAL \Schema \Index ;
18+ use Doctrine \DBAL \Schema \PrimaryKeyConstraint ;
1819use Doctrine \DBAL \Schema \Sequence ;
1920use Doctrine \DBAL \Schema \Table ;
2021use Doctrine \DBAL \Schema \TableDiff ;
@@ -567,14 +568,21 @@ public function testCreateClusteredIndex(): void
567568
568569 public function testCreateNonClusteredPrimaryKeyInTable (): void
569570 {
570- $ table = new Table ('tbl ' , [
571- Column::editor ()
572- ->setUnquotedName ('id ' )
573- ->setTypeName (Types::INTEGER )
574- ->create (),
575- ]);
576- $ table ->setPrimaryKey (['id ' ]);
577- $ table ->getIndex ('primary ' )->addFlag ('nonclustered ' );
571+ $ table = Table::editor ()
572+ ->setUnquotedName ('tbl ' )
573+ ->setColumns (
574+ Column::editor ()
575+ ->setUnquotedName ('id ' )
576+ ->setTypeName (Types::INTEGER )
577+ ->create (),
578+ )
579+ ->setPrimaryKeyConstraint (
580+ PrimaryKeyConstraint::editor ()
581+ ->setUnquotedColumnNames ('id ' )
582+ ->setIsClustered (false )
583+ ->create (),
584+ )
585+ ->create ();
578586
579587 self ::assertEquals (
580588 ['CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id)) ' ],
You can’t perform that action at this time.
0 commit comments