Skip to content

Commit a76e64d

Browse files
committed
Add an integration test for replacing a foreign key constraint
1 parent 37ab825 commit a76e64d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/Functional/Schema/AlterTableTest.php

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

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

0 commit comments

Comments
 (0)