@@ -176,6 +176,43 @@ public function testAddNewColumnToPrimaryKey(): void
176
176
});
177
177
}
178
178
179
+ public function testReplaceForeignKeyConstraint (): void
180
+ {
181
+ $ customers = new Table ('customers ' );
182
+ $ customers ->addColumn ('id ' , Types::INTEGER );
183
+ $ customers ->addColumn ('tenant_id ' , Types::INTEGER );
184
+ $ customers ->setPrimaryKey (['id ' , 'tenant_id ' ]);
185
+
186
+ $ orders = new Table ('orders ' );
187
+ $ orders ->addColumn ('id ' , Types::INTEGER );
188
+ $ orders ->addColumn ('customer_id ' , Types::INTEGER );
189
+ $ orders ->addColumn ('tenant_id ' , Types::INTEGER );
190
+ $ orders ->addForeignKeyConstraint (
191
+ 'customers ' ,
192
+ ['customer_id ' ],
193
+ ['id ' ],
194
+ [],
195
+ 'customers_fk ' ,
196
+ );
197
+
198
+ $ this ->dropTableIfExists ('orders ' );
199
+ $ this ->dropTableIfExists ('customers ' );
200
+
201
+ $ this ->connection ->createSchemaManager ()
202
+ ->createTable ($ customers );
203
+
204
+ $ this ->testMigration ($ orders , static function (Table $ table ): void {
205
+ $ table ->removeForeignKey ('customers_fk ' );
206
+ $ table ->addForeignKeyConstraint (
207
+ 'customers ' ,
208
+ ['customer_id ' , 'tenant_id ' ],
209
+ ['id ' , 'tenant_id ' ],
210
+ [],
211
+ 'customers_fk ' ,
212
+ );
213
+ });
214
+ }
215
+
179
216
private function ensureDroppingPrimaryKeyConstraintIsSupported (): void
180
217
{
181
218
$ platform = $ this ->connection ->getDatabasePlatform ();
0 commit comments