55namespace Doctrine \DBAL \Schema ;
66
77use Doctrine \DBAL \Platforms \AbstractPlatform ;
8+ use Doctrine \DBAL \Schema \Exception \UnspecifiedConstraintName ;
89use Doctrine \DBAL \Schema \Name \UnquotedIdentifierFolding ;
910
1011use function count ;
@@ -127,16 +128,16 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2): bool
127128 */
128129 public function compareTables (Table $ oldTable , Table $ newTable ): TableDiff
129130 {
130- $ addedColumns = [];
131- $ modifiedColumns = [];
132- $ droppedColumns = [];
133- $ addedIndexes = [];
134- $ droppedIndexes = [];
135- $ renamedIndexes = [];
136- $ addedForeignKeys = [];
137- $ droppedForeignKeys = [];
138- $ addedPrimaryKeyConstraint = null ;
139- $ droppedPrimaryKeyConstraint = null ;
131+ $ addedColumns = [];
132+ $ modifiedColumns = [];
133+ $ droppedColumns = [];
134+ $ addedIndexes = [];
135+ $ droppedIndexes = [];
136+ $ renamedIndexes = [];
137+ $ addedForeignKeys = [];
138+ $ droppedForeignKeyConstraintNames = [];
139+ $ addedPrimaryKeyConstraint = null ;
140+ $ droppedPrimaryKeyConstraint = null ;
140141
141142 $ oldColumns = $ oldTable ->getColumns ();
142143 $ newColumns = $ newTable ->getColumns ();
@@ -279,8 +280,8 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff
279280 && strtolower ($ oldForeignKeyName ->getIdentifier ()->getValue ())
280281 === strtolower ($ newForeignKeyName ->getIdentifier ()->getValue ())
281282 ) {
282- $ droppedForeignKeys [$ oldKey ] = $ oldForeignKey ;
283- $ addedForeignKeys [$ newKey ] = $ newForeignKey ;
283+ $ droppedForeignKeyConstraintNames [$ oldKey ] = $ oldForeignKeyName ;
284+ $ addedForeignKeys [$ newKey ] = $ newForeignKey ;
284285
285286 unset($ oldForeignKeys [$ oldKey ], $ newForeignKeys [$ newKey ]);
286287 }
@@ -289,7 +290,12 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff
289290 }
290291
291292 foreach ($ oldForeignKeys as $ oldForeignKey ) {
292- $ droppedForeignKeys [] = $ oldForeignKey ;
293+ $ constraintName = $ oldForeignKey ->getObjectName ();
294+ if ($ constraintName === null ) {
295+ throw UnspecifiedConstraintName::forForeignKeyConstraint ();
296+ }
297+
298+ $ droppedForeignKeyConstraintNames [] = $ constraintName ;
293299 }
294300
295301 foreach ($ newForeignKeys as $ newForeignKey ) {
@@ -305,7 +311,7 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff
305311 droppedIndexes: $ droppedIndexes ,
306312 renamedIndexes: $ renamedIndexes ,
307313 addedForeignKeys: $ addedForeignKeys ,
308- droppedForeignKeys : $ droppedForeignKeys ,
314+ droppedForeignKeyConstraintNames : $ droppedForeignKeyConstraintNames ,
309315 addedPrimaryKeyConstraint: $ addedPrimaryKeyConstraint ,
310316 droppedPrimaryKeyConstraint: $ droppedPrimaryKeyConstraint ,
311317 );
0 commit comments