Skip to content

Commit

Permalink
Implement the partial index for SQLite
Browse files Browse the repository at this point in the history
Queries the sqlite_master instead of using PRAGMA because PRAGMA doesn't store the definition
  • Loading branch information
Vincentv92 committed Dec 5, 2024
1 parent 4a087f4 commit 0774f2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -987,4 +987,9 @@ public function normalizeUnquotedIdentifier(string $identifier): string
{
return $identifier;
}

public function supportsPartialIndexes(): bool
{
return true;
}
}
10 changes: 10 additions & 0 deletions src/Schema/SQLiteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ static function (array $a, array $b): int {
$idx['primary'] = false;
$idx['non_unique'] = ! $tableIndex['unique'];

if ($tableIndex['partial'] === 1) {
$idx['where'] = $this->connection->fetchOne(
<<<'SQL'

Check warning on line 156 in src/Schema/SQLiteSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/SQLiteSchemaManager.php#L154-L156

Added lines #L154 - L156 were not covered by tests
SELECT SUBSTR(sql, INSTR(sql, 'WHERE') + 6)
FROM sqlite_master WHERE type = 'index' AND name = (?)
SQL,
[$keyName],
);

Check warning on line 161 in src/Schema/SQLiteSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/SQLiteSchemaManager.php#L159-L161

Added lines #L159 - L161 were not covered by tests
}

$indexArray = $this->connection->fetchAllAssociative('SELECT * FROM PRAGMA_INDEX_INFO (?)', [$keyName]);

foreach ($indexArray as $indexColumnRow) {
Expand Down

0 comments on commit 0774f2c

Please sign in to comment.