Skip to content

Commit 03bc93b

Browse files
authored
Merge pull request #4255 from morozov/issues/4243
Revert full support for foreign key constraints for SQLite
2 parents fdbd770 + 912db7a commit 03bc93b

19 files changed

+32
-402
lines changed

lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ public function convertException($message, DriverException $exception)
7070
return new Exception\ConnectionException($message, $exception);
7171
}
7272

73-
if (strpos($exception->getMessage(), 'FOREIGN KEY constraint failed') !== false) {
74-
return new Exception\ForeignKeyConstraintViolationException($message, $exception);
75-
}
76-
7773
return new Exception\DriverException($message, $exception);
7874
}
7975

lib/Doctrine/DBAL/Internal/DependencyOrderCalculator.php

Lines changed: 0 additions & 131 deletions
This file was deleted.

lib/Doctrine/DBAL/Internal/DependencyOrderEdge.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/Doctrine/DBAL/Internal/DependencyOrderNode.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/Doctrine/DBAL/Platforms/AbstractPlatform.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,16 +3217,6 @@ public function supportsForeignKeyConstraints()
32173217
return true;
32183218
}
32193219

3220-
/**
3221-
* Whether foreign key constraints can be dropped.
3222-
*
3223-
* If false, then getDropForeignKeySQL() throws exception.
3224-
*/
3225-
public function supportsCreateDropForeignKeyConstraints(): bool
3226-
{
3227-
return true;
3228-
}
3229-
32303220
/**
32313221
* Whether this platform supports onUpdate in foreign key constraints.
32323222
*

lib/Doctrine/DBAL/Platforms/SqlitePlatform.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,6 @@ public function canEmulateSchemas()
791791
* {@inheritDoc}
792792
*/
793793
public function supportsForeignKeyConstraints()
794-
{
795-
return true;
796-
}
797-
798-
public function supportsCreateDropForeignKeyConstraints(): bool
799794
{
800795
return false;
801796
}
@@ -813,21 +808,15 @@ public function getCreatePrimaryKeySQL(Index $index, $table)
813808
*/
814809
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
815810
{
816-
throw new DBALException(
817-
'Sqlite platform does not support alter foreign key, '
818-
. 'the table must be fully recreated using getAlterTableSQL.'
819-
);
811+
throw new DBALException('Sqlite platform does not support alter foreign key.');
820812
}
821813

822814
/**
823815
* {@inheritdoc}
824816
*/
825817
public function getDropForeignKeySQL($foreignKey, $table)
826818
{
827-
throw new DBALException(
828-
'Sqlite platform does not support alter foreign key, '
829-
. 'the table must be fully recreated using getAlterTableSQL.'
830-
);
819+
throw new DBALException('Sqlite platform does not support alter foreign key.');
831820
}
832821

833822
/**

lib/Doctrine/DBAL/Schema/SchemaDiff.php

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Doctrine\DBAL\Schema;
44

5-
use Doctrine\DBAL\Internal\DependencyOrderCalculator;
65
use Doctrine\DBAL\Platforms\AbstractPlatform;
76

87
use function array_merge;
@@ -139,16 +138,13 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false)
139138
}
140139

141140
$foreignKeySql = [];
142-
$createFlags = AbstractPlatform::CREATE_INDEXES;
143-
144-
if (! $platform->supportsCreateDropForeignKeyConstraints()) {
145-
$createFlags |= AbstractPlatform::CREATE_FOREIGNKEYS;
146-
}
147-
148-
foreach ($this->getNewTablesSortedByDependencies() as $table) {
149-
$sql = array_merge($sql, $platform->getCreateTableSQL($table, $createFlags));
141+
foreach ($this->newTables as $table) {
142+
$sql = array_merge(
143+
$sql,
144+
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)
145+
);
150146

151-
if (! $platform->supportsCreateDropForeignKeyConstraints()) {
147+
if (! $platform->supportsForeignKeyConstraints()) {
152148
continue;
153149
}
154150

@@ -171,37 +167,4 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false)
171167

172168
return $sql;
173169
}
174-
175-
/**
176-
* Sorts tables by dependencies so that they are created in the right order.
177-
*
178-
* This is necessary when one table depends on another while creating foreign key
179-
* constraints directly during CREATE TABLE.
180-
*
181-
* @return array<Table>
182-
*/
183-
private function getNewTablesSortedByDependencies()
184-
{
185-
$calculator = new DependencyOrderCalculator();
186-
$newTables = [];
187-
188-
foreach ($this->newTables as $table) {
189-
$newTables[$table->getName()] = true;
190-
$calculator->addNode($table->getName(), $table);
191-
}
192-
193-
foreach ($this->newTables as $table) {
194-
foreach ($table->getForeignKeys() as $foreignKey) {
195-
$foreignTableName = $foreignKey->getForeignTableName();
196-
197-
if (! isset($newTables[$foreignTableName])) {
198-
continue;
199-
}
200-
201-
$calculator->addDependency($foreignTableName, $table->getName());
202-
}
203-
}
204-
205-
return $calculator->sort();
206-
}
207170
}

lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function listTableForeignKeys($table, $database = null)
149149
$id = $value['id'];
150150

151151
$tableForeignKeys[$key] = array_merge($tableForeignKeys[$key], [
152-
'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : null,
152+
'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : $id,
153153
'deferrable' => isset($deferrable[$id]) && strtolower($deferrable[$id]) === 'deferrable',
154154
'deferred' => isset($deferred[$id]) && strtolower($deferred[$id]) === 'deferred',
155155
]);

lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function acceptTable(Table $table)
5656
*/
5757
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
5858
{
59-
if (! $this->platform->supportsCreateDropForeignKeyConstraints()) {
59+
if (! $this->platform->supportsForeignKeyConstraints()) {
6060
return;
6161
}
6262

lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public function acceptTable(Table $table)
4848
*/
4949
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
5050
{
51-
if (! $this->platform->supportsCreateDropForeignKeyConstraints()) {
52-
return;
53-
}
54-
5551
if (strlen($fkConstraint->getName()) === 0) {
5652
throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
5753
}

0 commit comments

Comments
 (0)