Add ORDER BY to guarantee stable result ordering across all database
backends (MySQL does not sort without it). Also consolidate double
catalog.facets() calls in tests into a single call with both content
and length assertions on the same result.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the LEFT OUTER JOIN + DISTINCT in the queryEntities CTE with
an INNER JOIN that drives from the search table for the sort field's
key. Entities lacking the sort field are excluded from both the result
and the count, aligning totalItems with navigable entities.
Removes DISTINCT (prerequisite: search table dedup migration).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
GROUP BY result ordering is non-deterministic across database engines.
The switch from COUNT(DISTINCT entity_id) to COUNT(*) changes MySQL's
aggregation plan, which surfaces a different row order. Use
arrayContaining + length check instead of exact array equality.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
The UNIQUE constraint on (entity_id, key, value) from the search
indices migration guarantees each entity appears at most once per
(key, original_value) group, making DISTINCT unnecessary. Removing
it lets the database use a simpler aggregation plan.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
* feat(ui): add DatePicker component
Add a single-date picker built on React Aria's DatePicker, mirroring the
existing DateRangePicker implementation. Includes the date field with
segmented input, calendar popover, BUI design tokens, bg consumer
pattern, and full keyboard/screen reader accessibility.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>
* fix(ui): address DatePicker PR feedback
- Remove unused dataAttributes spread from DatePickerGroup
- Mark DatePickerGroupDefinition and DatePickerCalendarDefinition as
public so CSS class name changes appear in API reports
- Add Affected components line to changeset
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>
* fix(ui): restore dataAttributes spread in DatePickerGroup
The bg: 'consumer' config on DatePickerGroupDefinition emits
data-on-bg attributes via useDefinition. Without spreading
dataAttributes onto <Group>, the CSS [data-on-bg] selectors
never match and background auto-increment doesn't work.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>
---------
Signed-off-by: Erik Hughes <erikh@spotify.com>
Co-authored-by: Erik Hughes <erikh@spotify.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(scaffolder): add BUI theme for scaffolder forms
Add a Backstage UI (BUI) form theme as an alternative to the Material
UI theme. Toggled via formProps.theme or enableBackstageUi page config.
Includes BUI widgets, templates, field extension variants, and a ported
React Aria Autocomplete component.
Signed-off-by: benjdlambert <ben@blam.sh>
* refactor(scaffolder): use BUI Combobox and CheckboxGroup for form widgets
Signed-off-by: benjdlambert <ben@blam.sh>
* chore(scaffolder): enable BUI form flag and add kitchen sink demo template
Signed-off-by: benjdlambert <ben@blam.sh>
* fix(scaffolder): use outlined input style for BUI form widgets
Signed-off-by: benjdlambert <ben@blam.sh>
* fix(scaffolder): address BUI form PR feedback
Signed-off-by: benjdlambert <ben@blam.sh>
* fix(scaffolder): format CSS and regen API reports
Signed-off-by: benjdlambert <ben@blam.sh>
---------
Signed-off-by: benjdlambert <ben@blam.sh>
Move NULL_SENTINEL to util.ts and import it in buildEntitySearch and
syncSearchRows instead of hardcoding '\x01'. Keeps the dedup keys
consistent with filterSentinelValues and the SQL COALESCE(…, chr(1))
logic, avoiding drift if the sentinel ever changes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
The 'silently rejects a direct duplicate insert' test inserted a row
via raw Knex onConflict().ignore(), which has no corresponding
production code path (syncSearchRows uses ON CONFLICT DO UPDATE, not
DO NOTHING). The idempotency behaviour it was intended to verify is
already covered by 'leaves unchanged rows untouched'.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the raw Knex onConflict().merge() insert in the
'overwrites original_value on conflict' test with a direct UPDATE to
corrupt the stored original_value, followed by a second syncSearchRows
call. This tests the actual application code path (ON CONFLICT DO UPDATE
inside syncSearchRows) rather than embedding the conflict logic in the
test itself.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Tests two scenarios across all supported databases:
Preconditions NOT met (dedup runs): inserts five rows with two
duplicate (entity_id, key, value) pairs (one with null value),
runs the migration, and verifies that duplicates are removed, null
values are handled correctly, and the unique constraint is enforced
post-migration. The down migration is verified to drop the constraint
so duplicates can be inserted again.
Preconditions met (PostgreSQL only, dedup skipped): pre-creates the
unique index to simulate a user who ran the manual SQL before
deploying, re-runs the migration, and verifies the row count is
unchanged — confirming the fast path fires correctly.
Non-PostgreSQL databases skip the fast-path test with an early return
since the pg_index check is PostgreSQL-specific.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Update the 'keeps one row when original_value casing differs' test to
expect original_value: 'V' (first occurrence) instead of 'v' (last
occurrence), matching the first-wins dedup semantics that were aligned
with buildEntitySearch in a prior commit.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The index-only GROUP BY scan in Phase 1 of the dedup requires
search_key_value_entity_idx (key, value, entity_id) to exist.
Previously it was created after dedup, meaning fresh installs that
had never manually run preparatory SQL would fall back to a full
sequential scan.
Move the ensurePgIndex call for search_key_value_entity_idx to before
the dedup step so the fast path is guaranteed for all users, not just
those who created the index manually in advance.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the window-function full-table scan with a two-phase approach
that leverages search_key_value_entity_idx (key, value, entity_id):
Phase 1: GROUP BY entity_id, key, value with HAVING COUNT(*) > 1
resolves as a pure index-only scan (Heap Fetches: 0).
Stores only the duplicate groups in a temp table (~8s for
a 14M-row table with 700k dupes).
Phase 2: CROSS JOIN LATERAL back into search using the same covering
index (Nested Loop + Index Scan). row_number() runs per-group
over the 2-3 matching rows, so there is no global external
sort. A single DELETE removes all extras in one statement
(~16s).
NULL values get a separate UNION ALL arm so the index equality
condition stays usable (value = NULL is always false in SQL).
Benchmarked on a 14.4M-row production-like staging master with
700k injected duplicates, post-VACUUM:
Old (seq scan + external merge sort): ~101s
New (index-only + index scan): ~25s (~4× faster)
Clean second run (no dupes, fast path skips dedup): <50ms.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Use `=== null ? '\x01' : value` instead of `?? ''` in both buildEntitySearch
and syncSearchRows dedup maps, so that null and empty-string values are
treated as distinct keys. In theory an entity could produce both value=null
and value='' for the same key (e.g. spec.foo: [null, '']), and the old
encoding would silently drop one of the two distinct rows.
Also adds two focused unit tests to buildEntitySearch.test.ts: one covering
deduplication of duplicate array values (e.g. tags: ['java', 'java', 'Java']),
and one confirming that null and empty-string are kept as separate rows.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The original single-pass CTE window-function DELETE re-scanned every row
on each invocation — including the idempotent "nothing to do" case which
took over 4 minutes on a 14 M-row table, and timed out the DB proxy on
the dirty case (~217 s for 722 k duplicates).
Replace it with two improvements:
1. Fast path: if the UNIQUE index already exists and is valid, skip dedup
entirely. A valid unique index is a proof-of-no-duplicates. This makes
migration startup essentially free for installations that prepare the
index manually beforehand (as documented in the migration comment).
2. Two-phase dedup when dedup is needed: Phase 1 does one full-table scan
to collect all duplicate ctids into a temp table (~60 s on 14 M rows).
Phase 2 drains that temp table in 10 k-row batches via cheap ctid
lookups with no further full-table scans (~5 s for 722 k rows). Total
~65 s dirty vs >217 s+ before, and ~35 ms clean vs 4+ minutes before.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
30.4.0 introduced synchronous require(ESM) that requires Node v24.9+,
breaking tests on Node 22. 30.3.0 pulls in @sinonjs/fake-timers@^15
which conflicts with @types/sinon@^17 (used by aws-sdk-client-mock).
30.2.0 avoids both issues cleanly.
Resets lockfile to a clean base-install from master constraints.
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the monorepo's own jest resolution consistent with the template
range, and update the lockfile to 30.3.0 accordingly.
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Jest 30.4.0 introduced synchronous require(ESM) support that requires
Node v24.9+. With ^30.2.0 in the templates, a fresh yarn install in
e2e test apps resolves to 30.4.x and breaks on Node 22.
Pin to ~30.3.0 (30.3.x patches only), which includes the 30.3.0 fix
that explicitly disables the require_module feature flag, while staying
below the 30.4.0 runtime requirement.
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Prevents a false match if any non-index object (table, sequence, view)
shares a name with one of the search indices.
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Verifies that a conflicting insert with a different original_value casing
updates the stored value, and documents that DO UPDATE requires explicit
conflict columns unlike DO NOTHING.
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the explicit column list from .onConflict() calls in test setup —
ON CONFLICT DO NOTHING without a target is equivalent since (entity_id,
key, value) is the only unique constraint on the search table.
Add a dedicated test in syncSearchRows that directly inserts a duplicate
row and verifies it is silently rejected via the UNIQUE constraint.
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Avoids a window with no coverage on (key, value) during rollback.
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(scaffolder): promote formDecorators out of experimental
Signed-off-by: benjdlambert <ben@blam.sh>
* fix(scaffolder): parse form decorator input through the configured zod schema
Signed-off-by: benjdlambert <ben@blam.sh>
* refactor(scaffolder-backend): emit single formDecorators field on the parameter-schema response
Signed-off-by: benjdlambert <ben@blam.sh>
* feat(scaffolder): promote form decorator blueprints to public API
Signed-off-by: benjdlambert <ben@blam.sh>
---------
Signed-off-by: benjdlambert <ben@blam.sh>
Be explicit that interrupted index builds do not leave partial progress —
each retry starts from scratch. On large tables with short liveness
probe timeouts this repeats indefinitely. Recommend running the SQL
commands manually before deploying.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
The down migration now restores the previous index state (drops new
indices, recreates the old search_key_value_idx and
search_key_original_value_idx). Updated the SQL report to reflect the
new index set.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Single knex migration that cleans up duplicate search rows and creates
covering indices including a UNIQUE constraint on (entity_id, key, value).
Each step is idempotent and handles INVALID indices from interrupted runs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>