Skip to content

Commit 33d2d7f

Browse files
authored
Merge pull request #6825 from morozov/fk-replace-test
Add an integration test for replacing a foreign key constraint
2 parents 37ab825 + 9282116 commit 33d2d7f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Functional/Schema/AlterTableTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ public function testAddNewColumnToPrimaryKey(): void
176176
});
177177
}
178178

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+
179217
private function ensureDroppingPrimaryKeyConstraintIsSupported(): void
180218
{
181219
$platform = $this->connection->getDatabasePlatform();

0 commit comments

Comments
 (0)