Skip to content

Commit 742df57

Browse files
authored
Merge pull request #7143 from santysisi/fix/sqlite-drop-unnamed-foreign-keys
Deprecate unnamed foreign key constraints in `$droppedForeignKeys` of `TableDiff`
2 parents 673492c + 5d56d2e commit 742df57

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 4.4
1010

11+
## Deprecated dropping unnamed constraints in SQLite
12+
13+
Passing unnamed foreign key constraints as part of the `$droppedForeignKeys` argument of the `TableDiff` constructor
14+
has been deprecated.
15+
1116
## Deprecated overwriting foreign key constraints
1217

1318
Adding a foreign key constraint with a name that matches an existing one, whether explicitly specified or

src/Schema/TableDiff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public function __construct(
5656
);
5757
}
5858

59+
foreach ($droppedForeignKeys as $droppedForeignKey) {
60+
if ($droppedForeignKey->getName() === '') {
61+
Deprecation::trigger(
62+
'doctrine/dbal',
63+
'https://github.com/doctrine/dbal/pull/7143',
64+
'Dropping a foreign key constraints without specifying its name is deprecated.',
65+
);
66+
break;
67+
}
68+
}
69+
5970
if (count($modifiedForeignKeys) === 0) {
6071
return;
6172
}

tests/Schema/TableDiffTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Tests\Schema;
6+
7+
use Doctrine\DBAL\Schema\Column;
8+
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
9+
use Doctrine\DBAL\Schema\Table;
10+
use Doctrine\DBAL\Schema\TableDiff;
11+
use Doctrine\DBAL\Types\Types;
12+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class TableDiffTest extends TestCase
16+
{
17+
use VerifyDeprecations;
18+
19+
public function testCreateWithInvalidDroppedForeignKeyName(): void
20+
{
21+
$table = Table::editor()
22+
->setUnquotedName('t1')
23+
->setColumns(
24+
Column::editor()
25+
->setUnquotedName('c1')
26+
->setTypeName(Types::INTEGER)
27+
->create(),
28+
)
29+
->create();
30+
31+
$droppedForeignKeys = ForeignKeyConstraint::editor()
32+
->setUnquotedReferencingColumnNames('c1')
33+
->setUnquotedReferencedTableName('t2')
34+
->setUnquotedReferencedColumnNames('c1')
35+
->create();
36+
37+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7143');
38+
new TableDiff($table, droppedForeignKeys: [$droppedForeignKeys]);
39+
}
40+
}

0 commit comments

Comments
 (0)