Skip to content

Commit 50779e5

Browse files
committed
Add string and boolean indexes for custom field filter queries
1 parent c21b176 commit 50779e5

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

packages/builder/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ One row per value:
145145

146146
Unique: `(entity, record_id, field_name, locale)`.
147147

148+
Indexes for list filter/sort EXISTS subqueries: `(entity, field_name, value_decimal|date|datetime)` and `(entity, field_name, locale, value_string|value_boolean)`. Text `LIKE '%…%'` filters still cannot use the string index efficiently.
149+
148150
### Definition translations (Astrotomic)
149151

150152
Field group names, field labels, option labels, and translatable field config (`helperText`, `placeholder`, …) use [astrotomic/laravel-translatable](https://docs.astrotomic.info/laravel-translatable) — the same stack as `moox/media` and Moox draft entities (via `moox/localization`).

packages/builder/database/migrations/create_builder_field_values_table.php.stub

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ return new class extends Migration
3030
$table->index(['entity', 'field_name', 'value_decimal']);
3131
$table->index(['entity', 'field_name', 'value_date']);
3232
$table->index(['entity', 'field_name', 'value_datetime']);
33+
$table->index(
34+
['entity', 'field_name', 'locale', 'value_string'],
35+
'bfv_entity_field_locale_string_index',
36+
);
37+
$table->index(
38+
['entity', 'field_name', 'locale', 'value_boolean'],
39+
'bfv_entity_field_locale_boolean_index',
40+
);
3341
$table->index(['entity', 'record_id']);
3442
});
3543
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once __DIR__.'/../TestCase.php';
6+
7+
use Illuminate\Support\Facades\Schema;
8+
use Moox\Builder\Tests\TestCase;
9+
10+
uses(TestCase::class);
11+
12+
it('creates string and boolean value indexes for filter and sort queries', function (): void {
13+
expect(Schema::hasIndex('builder_field_values', 'bfv_entity_field_locale_string_index'))->toBeTrue()
14+
->and(Schema::hasIndex('builder_field_values', 'bfv_entity_field_locale_boolean_index'))->toBeTrue();
15+
});

0 commit comments

Comments
 (0)