Skip to content

Commit

Permalink
Merge pull request #5411 from morozov/sqlite-fk-revert
Browse files Browse the repository at this point in the history
Mark SQLite platform as not supporting foreign keys
  • Loading branch information
morozov authored May 24, 2022
2 parents a14fb3f + 2e223d5 commit 7b85b8c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -3708,18 +3708,10 @@ public function supportsPrimaryConstraints()
/**
* Whether the platform supports foreign key constraints.
*
* @deprecated All platforms should support foreign key constraints.
*
* @return bool
*/
public function supportsForeignKeyConstraints()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/5409',
'AbstractPlatform::supportsForeignKeyConstraints() is deprecated.'
);

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ public function canEmulateSchemas()
return true;
}

/**
* {@inheritDoc}
*/
public function supportsForeignKeyConstraints()
{
return false;
}

/**
* {@inheritDoc}
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ public function testDropAndCreateUniqueConstraint(): void

public function testCreateTableWithForeignKeys(): void
{
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('Platform does not support foreign keys.');
}

$tableB = $this->getTestTable('test_foreign');

$this->dropAndCreateTable($tableB);
Expand Down Expand Up @@ -675,6 +679,10 @@ public function testAlterTableScenario(): void
// dont check for index size here, some platforms automatically add indexes for foreign keys.
self::assertFalse($table->hasIndex('bar_idx'));

if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
return;
}

$fks = $table->getForeignKeys();
self::assertCount(1, $fks);
$foreignKey = current($fks);
Expand Down Expand Up @@ -775,6 +783,12 @@ public function testAutoincrementDetectionMulticolumns(): void
*/
public function testUpdateSchemaWithForeignKeyRenaming(callable $comparatorFactory): void
{
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsForeignKeyConstraints()) {
self::markTestSkipped('This test is only supported on platforms that have foreign keys.');
}

$table = new Table('test_fk_base');
$table->addColumn('id', 'integer');
$table->setPrimaryKey(['id']);
Expand Down Expand Up @@ -821,6 +835,12 @@ public function testUpdateSchemaWithForeignKeyRenaming(callable $comparatorFacto
*/
public function testRenameIndexUsedInForeignKeyConstraint(callable $comparatorFactory): void
{
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsForeignKeyConstraints()) {
self::markTestSkipped('This test is only supported on platforms that have foreign keys.');
}

$primaryTable = new Table('test_rename_index_primary');
$primaryTable->addColumn('id', 'integer');
$primaryTable->setPrimaryKey(['id']);
Expand Down Expand Up @@ -1563,6 +1583,10 @@ public function testCommentInTable(): void

public function testCreatedCompositeForeignKeyOrderIsCorrectAfterCreation(): void
{
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('Platform does not support foreign keys.');
}

$foreignKey = 'fk_test_order';
$localTable = 'test_table_foreign';
$foreignTable = 'test_table_local';
Expand Down
6 changes: 6 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,12 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL(): array

public function testQuotesDropForeignKeySQL(): void
{
if (! $this->platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped(
sprintf('%s does not support foreign key constraints.', get_class($this->platform))
);
}

$tableName = 'table';
$table = new Table($tableName);
$foreignKeyName = 'select';
Expand Down

0 comments on commit 7b85b8c

Please sign in to comment.