File tree 1 file changed +38
-0
lines changed 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,44 @@ public function testAddNewColumnToPrimaryKey(): void
176
176
});
177
177
}
178
178
179
+ public function testReplaceForeignKeyConstraint (): void
180
+ {
181
+ $ articles = new Table ('articles ' );
182
+ $ articles ->addColumn ('id ' , Types::INTEGER );
183
+ $ articles ->addColumn ('sku ' , Types::INTEGER );
184
+ $ articles ->setPrimaryKey (['id ' ]);
185
+ $ articles ->addUniqueConstraint (['sku ' ]);
186
+
187
+ $ orders = new Table ('orders ' );
188
+ $ orders ->addColumn ('id ' , Types::INTEGER );
189
+ $ orders ->addColumn ('article_id ' , Types::INTEGER );
190
+ $ orders ->addColumn ('article_sku ' , Types::INTEGER );
191
+ $ orders ->addForeignKeyConstraint (
192
+ 'articles ' ,
193
+ ['article_id ' ],
194
+ ['id ' ],
195
+ [],
196
+ 'articles_fk ' ,
197
+ );
198
+
199
+ $ this ->dropTableIfExists ('orders ' );
200
+ $ this ->dropTableIfExists ('articles ' );
201
+
202
+ $ this ->connection ->createSchemaManager ()
203
+ ->createTable ($ articles );
204
+
205
+ $ this ->testMigration ($ orders , static function (Table $ table ): void {
206
+ $ table ->removeForeignKey ('articles_fk ' );
207
+ $ table ->addForeignKeyConstraint (
208
+ 'articles ' ,
209
+ ['article_sku ' ],
210
+ ['sku ' ],
211
+ [],
212
+ 'articles_fk ' ,
213
+ );
214
+ });
215
+ }
216
+
179
217
private function ensureDroppingPrimaryKeyConstraintIsSupported (): void
180
218
{
181
219
$ platform = $ this ->connection ->getDatabasePlatform ();
You can’t perform that action at this time.
0 commit comments