Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/Filament/Resources/IndexResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public static function table(Table $table): Table
TextColumn::make('indexrelname')
->label('Index')
->description(fn (IndexModel $record): string => $record->schemaname.'.'.$record->relname)
->searchable(['indexrelname', 'relname'])
// Both search columns are qualified: the query joins pg_class, which
// has a relname of its own, and an unqualified one leaves PostgreSQL
// unable to tell which table is meant.
->searchable(['pg_stat_user_indexes.indexrelname', 'pg_stat_user_indexes.relname'])
->sortable(),

TextColumn::make('index_bytes')
Expand Down
18 changes: 18 additions & 0 deletions tests/Filament/IndexResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,21 @@ function indexNamed(string $name): Index
->and(IndexResource::canAccess())->toBeTrue()
->and(array_keys(IndexResource::getPages()))->toBe(['index']);
});

it('searches an index by its own name and by the table it belongs to', function (): void {
$column = bootedColumns(ListIndexes::class, indexNamed('crates_label_index'))['indexrelname'];

// pg_stat_user_indexes and the joined pg_class both have a relname, so an
// unqualified search column leaves PostgreSQL unable to tell which is meant.
$byIndexName = IndexResource::getEloquentQuery();
$isFirst = true;
$column->applySearchConstraint($byIndexName, 'crates_label', $isFirst);

$byTableName = IndexResource::getEloquentQuery();
$isFirst = true;
$column->applySearchConstraint($byTableName, 'crates', $isFirst);

expect($byIndexName->pluck('indexrelname')->all())->toBe(['crates_label_index'])
->and($byTableName->pluck('indexrelname')->all())
->toContain('crates_pkey', 'crates_label_index', 'crates_code_unique');
});
Loading