'numeric' is a reserved keyword and built-in type in PostgreSQL, which
can cause syntax parsing issues and ORM compatibility problems when used
as a collation name. Renamed to 'natural_sort' to be unambiguous and
self-documenting.
SET only applies to the current migration session and is lost when the
connection closes. Use a DO block with current_database() to execute
ALTER DATABASE ... SET, which persists the GUC for all future connections.
The DO block with format('%I', current_database()) avoids hardcoding
the database name and works on PostgreSQL < 16 (which lacks ALTER DATABASE
CURRENT syntax).
- Add HNSW index on asset_embeddings.embedding using vector_cosine_ops (m=16,
ef_construction=64) with hnsw.iterative_scan=relaxed_order for efficient
filtered ANN queries
- Create ICU numeric collation and alter assets.name column to use it for
natural sort (file2 < file10 instead of lexicographic ordering)
- Add B-tree index on assets.name with numeric collation for sort performance
- Add schema @@index annotations to match migration index names
- Add 7 tests verifying natural sort behaviour in both AssetService.listChildren
and SearchService.search (Prisma ORM and raw-SQL paths)
- Delete 19 historical migration files and directories
- Generate a new squashed migration 000000000000_squashed_migrations using prisma migrate diff
- Verify that all tests pass cleanly using Testcontainers with the squashed migration
Rename the database column from field_id to field_key and the Prisma
property from fieldId to fieldKey to better reflect that the column
stores human-readable metadata field keys, not internal database IDs.
This fixes a bug where AI autofill wrote internal DB IDs instead of
field keys, causing metadata values to not display in the UI.
- Add SQL migration to rename the column
- Update metadata, search, and asset services
- Fix agent-autofill workflow to map fields by key
- Update all related test suites