Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Schema/SQLiteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ protected function fetchTableColumns(string $databaseName, ?string $tableName =

$sqlByTable[$tableName] ??= $this->getCreateTableSQL($tableName);

if ($row['pk'] === 0 || $row['pk'] === '0' || $row['type'] !== 'INTEGER') {
if ($row['pk'] === 0 || $row['pk'] === '0') {
continue;
}

Expand All @@ -481,7 +481,7 @@ protected function fetchTableColumns(string $databaseName, ?string $tableName =

$result[] = array_merge($row, [
'autoincrement' => isset($pkColumnNamesByTable[$tableName])
&& $pkColumnNamesByTable[$tableName] === [$columnName],
&& $pkColumnNamesByTable[$tableName] === [$columnName] && $row['type'] === 'INTEGER',
'collation' => $this->parseColumnCollationFromSQL($columnName, $tableSQL),
'comment' => $this->parseColumnCommentFromSQL($columnName, $tableSQL),
]);
Expand Down
52 changes: 52 additions & 0 deletions tests/Functional/Schema/SQLiteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,58 @@ public function testShorthandInForeignKeyReferenceWithMultipleColumns(): void
);
}

public function testIntrospectPrimaryKeyAutoincrement(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests seems to combine three independent tests. Would it make sense to separate them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three assertions are all testing the same logic, so it seemed clearer (to me) to have them in a single test.

I can split them up if desired, but I prefer them together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current approach, if the first assertion fails, the other two will be skipped, however they shouldn't.

{
$this->dropTableIfExists('dbal_7271_1');
$this->dropTableIfExists('dbal_7271_2');
$this->dropTableIfExists('dbal_7271_3');

$ddl = <<<'DDL'
CREATE TABLE dbal_7271_1 (
user_id INTEGER,
user_name VARCHAR,
PRIMARY KEY (user_id)
);
CREATE TABLE dbal_7271_2 (
user_id INTEGER,
setting_name VARCHAR,
setting_value TEXT,
PRIMARY KEY (user_id, setting_name)
);
CREATE TABLE dbal_7271_3 (
setting_name VARCHAR,
setting_value VARCHAR,
PRIMARY KEY (setting_name)
);
DDL;

$this->connection->executeStatement($ddl);

$schemaManager = $this->connection->createSchemaManager();

$autoincrement1 = $schemaManager
->introspectSchema()
->getTable('dbal_7271_1')
->getColumn('user_id')
->getAutoincrement();

$autoincrement2 = $schemaManager
->introspectSchema()
->getTable('dbal_7271_2')
->getColumn('user_id')
->getAutoincrement();

$autoincrement3 = $schemaManager
->introspectSchema()
->getTable('dbal_7271_3')
->getColumn('setting_name')
->getAutoincrement();

self::assertTrue($autoincrement1, 'Integer PKs are implicitly autoincrement');
self::assertFalse($autoincrement2, 'Composite PKs cannot autoincrement');
self::assertFalse($autoincrement3, 'Non-integer PKs cannot autoincrement');
}

public function testListTableNoSchemaEmulation(): void
{
$databasePlatform = $this->connection->getDatabasePlatform();
Expand Down