Skip to content

Commit

Permalink
Add an integration test for replacing a foreign key constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Mar 7, 2025
1 parent 37ab825 commit 9282116
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/Functional/Schema/AlterTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,44 @@ public function testAddNewColumnToPrimaryKey(): void
});
}

public function testReplaceForeignKeyConstraint(): void
{
$articles = new Table('articles');
$articles->addColumn('id', Types::INTEGER);
$articles->addColumn('sku', Types::INTEGER);
$articles->setPrimaryKey(['id']);
$articles->addUniqueConstraint(['sku']);

$orders = new Table('orders');
$orders->addColumn('id', Types::INTEGER);
$orders->addColumn('article_id', Types::INTEGER);
$orders->addColumn('article_sku', Types::INTEGER);
$orders->addForeignKeyConstraint(
'articles',
['article_id'],
['id'],
[],
'articles_fk',
);

$this->dropTableIfExists('orders');
$this->dropTableIfExists('articles');

$this->connection->createSchemaManager()
->createTable($articles);

$this->testMigration($orders, static function (Table $table): void {
$table->removeForeignKey('articles_fk');
$table->addForeignKeyConstraint(
'articles',
['article_sku'],
['sku'],
[],
'articles_fk',
);
});
}

private function ensureDroppingPrimaryKeyConstraintIsSupported(): void
{
$platform = $this->connection->getDatabasePlatform();
Expand Down

0 comments on commit 9282116

Please # to comment.