Skip to content

Elasticsearch dual-write sync, bulk reindex, and reindex endpoint#232

Draft
jakebromberg wants to merge 2 commits intofeature/elasticsearch-searchfrom
feature/elasticsearch-sync
Draft

Elasticsearch dual-write sync, bulk reindex, and reindex endpoint#232
jakebromberg wants to merge 2 commits intofeature/elasticsearch-searchfrom
feature/elasticsearch-sync

Conversation

@jakebromberg
Copy link
Member

Summary

  • Implement elasticsearch.sync.ts stubs: indexLibraryDocumentById, removeLibraryDocument, bulkIndexLibrary (batches of 500, returns { indexed, errors } counts)
  • Wire dual-write into library.service.ts: insertAlbum, addToRotation, killRotationInDB fire-and-forget sync to ES after DB writes
  • Add POST /library/reindex endpoint (requires catalog: ['write']) for full bulk reindex
  • Add 18 sync unit tests and 6 dual-write library service tests

Closes #231

Test plan

  • npm run test:unit — 291 tests pass (23 suites), including 24 new tests
  • npm run typecheck — clean
  • npm run lint — 0 errors
  • Manual: start with ELASTICSEARCH_URL=http://localhost:9200, call POST /library/reindex, verify ES has documents
  • Manual: POST /library to add album, verify it appears in ES via search
  • Manual: without ELASTICSEARCH_URL set, verify all writes succeed with no ES errors

…dex endpoint

Wire Elasticsearch sync into the library service layer so album inserts, rotation adds, and rotation kills are dual-written to ES as fire-and-forget operations. Errors are logged but never propagated, so library operations succeed even when ES is unavailable.

Add POST /library/reindex endpoint (requires catalog write permission) that bulk-indexes all library_artist_view rows into ES in batches of 500.

Add unit tests for all sync functions and verify dual-write calls from library service functions.
@jakebromberg jakebromberg marked this pull request as draft March 11, 2026 17:37
Drizzle ORM references underlying table column names (e.g. artist_genre_code) instead of view column aliases (e.g. code_artist_number) when using db.select().from(view). Switch to raw SQL with db.execute() for library_artist_view queries.

Also fix add_date serialization: postgres-js returns timestamp strings (not Date objects) from raw queries, so parse through new Date() to produce valid ISO strings for ES.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants