Skip to content

Commit

Permalink
Fix parsing SQLite FK reference not containing whitepace
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Aug 17, 2022
1 parent 94e0164 commit f62eeba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private function getForeignKeyDetails($table)
'#
(?:CONSTRAINT\s+(\S+)\s+)?
(?:FOREIGN\s+KEY[^)]+\)\s*)?
REFERENCES\s+\S+\s+(?:\([^)]+\))?
REFERENCES\s+\S+\s*(?:\([^)]+\))?
(?:
[^,]*?
(NOT\s+DEFERRABLE|DEFERRABLE)
Expand Down
28 changes: 28 additions & 0 deletions tests/Functional/Schema/SqliteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,32 @@ public function testIntrospectMultipleAnonymousForeignKeyConstraints(): void
self::assertSame(['artist_id'], $foreignKey2->getLocalColumns());
self::assertSame(['id'], $foreignKey2->getForeignColumns());
}

public function testNoWhitespaceInForeignKeyReference(): void
{
$this->dropTableIfExists('notes');
$this->dropTableIfExists('users');

$ddl = <<<'DDL'
CREATE TABLE "users" (
"id" INTEGER
);
CREATE TABLE "notes" (
"id" INTEGER,
"created_by" INTEGER,
FOREIGN KEY("created_by") REFERENCES "users"("id"));
DDL;

$this->connection->executeStatement($ddl);
$notes = $this->schemaManager->listTableDetails('notes');

$foreignKeys = $notes->getForeignKeys();
self::assertCount(1, $foreignKeys);

$foreignKey = array_shift($foreignKeys);
self::assertSame(['created_by'], $foreignKey->getLocalColumns());
self::assertSame('users', $foreignKey->getForeignTableName());
self::assertSame(['id'], $foreignKey->getForeignColumns());
}
}

0 comments on commit f62eeba

Please sign in to comment.