Repository navigation
feat(catalog): build nemar_catalog from local D1, no legacy nemar.org pull - #546
Merged
Merged
Conversation
… pull Closes the architectural gap that #541 / #543 closed for historical rows: catalog-sync.ts only knows how to pull from https://nemar.org/api/dataexplorer/datapipeline, so any dataset created via the new in-process pipeline never gets a catalog row unless an operator runs a migration. Two changes make the local path the source going forward. 1. Hot path: syncNemarCatalogFromEnrichment now UPSERTs. Was an UPDATE-only that silently logged 'no row exists' when a freshly-enriched dataset didn't have a catalog entry. New behavior: INSERT ... ON CONFLICT(id) DO UPDATE so the first enrichment of any new dataset auto-creates its catalog row. Requires a non-null 'name' on the call site (nemar_catalog.name is NOT NULL); both callers (enrich-dataset.ts, dataset-reindex.ts) now thread name from the d1 row. 2. Bulk path: new backend/src/services/catalog-from-local.ts. - buildCatalogRecordFromLocal() pure projector: D1 row + parsed enrichment_json -> NemarCatalogRecord shape. Tested for every observed shape (object/array authors, null enrichment, on* mirrors, name/description fallback chain, search_text). - syncCatalogFromLocal() walks every active public dataset and INSERT-OR-REPLACEs the catalog row from local data. Batched to stay under D1 bound-param limits. - New POST /admin/catalog/sync-local endpoint triggers the sweep. Legacy catalog-sync.ts stays in place; #544 tracks the cron switch and eventual retirement. Migration 0023 + 0024 already healed the historical state, and the new hot-path UPSERT + bulk endpoint mean no future dataset can land in the empty-catalog state. 10 new unit tests for buildCatalogRecordFromLocal cover all the shape branches plus null defaults. Typecheck clean. Refs #544.
- syncCatalogFromLocal: switch INSERT OR REPLACE -> UPSERT (INSERT ... ON CONFLICT(id) DO UPDATE SET ...). INSERT OR REPLACE in SQLite is DELETE + INSERT which silently clobbered columns this path doesn't manage (readme, bids_version, sessions_count, latest_version, is_processed). Those are populated by the legacy catalog-sync.ts pull for ~70 datasets and would have gone NULL on every sweep. UPSERT preserves them. - Add datasets.published_at to the SELECT, prefer it for publish_date on the LocalCatalogRecord. Was using created_at, which would push freshly-published rows to the top of newest-first ordering only by upload timestamp, ignoring the months-long gap between upload and publish for legacy datasets. - New structural test test/catalog-from-local-sql.unit.test.ts pins the UPSERT choice and the deliberate column omission set so a future refactor can't silently regress to INSERT OR REPLACE or add a column without a real source for the value. - New structural test test/catalog-upsert-sql.unit.test.ts pins syncNemarCatalogFromEnrichment's UPSERT + COALESCE-preserve on every updatable column. Catches any revert that would re-introduce the silent-no-op on missing rows (#544 root cause). - Test fixture: add published_at + publish_date preference test. 18 unit tests pass.
Contributor
Author
pr-review-toolkit review (sonnet)Two reviewers, all findings addressed in d1f3c66. code-reviewer (REQUEST CHANGES)
pr-test-analyzer (NEEDS MORE COVERAGE)
Dynamic-import question: kept as-is (purely stylistic; matches the lazy-import pattern in admin.ts). 18 unit tests (added 8), typecheck clean, biome clean. |
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR546Version: 🤖 Updated on each push. |
This was referenced May 18, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the architectural gap in #544.
Two changes
1. Hot path:
syncNemarCatalogFromEnrichmentis now UPSERTWas
UPDATE-only and silently logged "no row exists" when a freshly-enriched dataset didn't have a catalog row (see #543 for the historical impact: ~100 datasets stuck in that state on prod). New behavior:namebecausenemar_catalog.nameis NOT NULL. Both callers (enrich-dataset.ts,dataset-reindex.ts) threaddataset.namefrom the d1 row through; LLM-derivedtitleis preferred when present.2. Bulk path:
syncCatalogFromLocal()+ admin endpointNew
backend/src/services/catalog-from-local.tsreads only from D1:buildCatalogRecordFromLocal(row, enrichment)-- pure projection. Tested across object/array author shapes, null enrichment, on* mirrors,enrichment.title/descriptionpreference, search_text composition.syncCatalogFromLocal(db)-- iterates every active public dataset, builds records, INSERT OR REPLACEs in batches.POST /admin/catalog/sync-localadmin endpoint triggers the sweep.Use cases:
Out of scope
catalog-sync.tsand the legacy nemar.org fetch (catalog-sync.ts depends on legacy nemar.org; replace with in-process generator #544 keeps tracking that)./admin/catalog/sync-localinstead of/admin/catalog/sync(mechanical change; happens once we've verified the local path on a few sweep runs).Tests
10 unit tests for the projector (id/source preservation, fallback chains for name/description, author shape detection, null defaults, search_text composition).
Typecheck clean.
Refs #544.