Repository navigation
fix(catalog): INSERT missing nemar_catalog rows from datasets + enrichment_json - #543
Merged
Merged
Conversation
…hment_json Migration 0023 UPDATE-only backfilled columns on existing nemar_catalog rows but couldn't fill rows that didn't exist. catalog-sync.ts (the legacy-nemar.org pull) was the only path that inserted them, so any dataset created via the new in-process pipeline -- which doesn't feed back into legacy nemar.org -- never got a catalog row. 103 active rows were in this state on production today. This migration creates the missing rows by projecting from the local source-of-truth: datasets.* (typed columns) + enrichment_json (LLM output, including authors as object-keyed or legacy array form). After it runs, every active public dataset has a nemar_catalog row and the list endpoint returns consistent values across the whole corpus. INSERT OR IGNORE keeps the migration idempotent: re-running it on a fully-populated catalog is a no-op. Follow-up tracked separately: replace catalog-sync.ts's legacy-pull with an in-process catalog generator so this gap doesn't recur for future datasets. Refs nemarOrg/website#1 (discover-card empty fields) Refs #541 (UPDATE-only backfill).
This was referenced May 18, 2026
neuromechanist
added a commit
that referenced
this pull request
May 18, 2026
… pull (#546) * feat(catalog): build nemar_catalog from local D1, no legacy nemar.org 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. * review: address findings on #546 - 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.
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.
Follow-up to #541 (which UPDATE-only backfilled). 103 active rows on production were missing from
nemar_catalogentirely, so the UPDATEs in migration 0023 couldn't reach them and the discover card kept rendering empty fields for them.Why they were missing
catalog-sync.tsis the only pre-existing path that inserts intonemar_catalog, and it pulls fromhttps://nemar.org/api/dataexplorer/datapipeline(legacy nemar.org). Datasets created via the new in-process pipeline (like nm000166) never feed back into legacy nemar.org, so catalog-sync never sees them, so they never get an initial nemar_catalog row.Fix
Migration 0024: one-shot
INSERT OR IGNOREthat projects from the local source of truth (datasets.*typed columns +enrichment_json) for every active public dataset that doesn't yet have a catalog row. Handles both author shapes the enrichment emits (object-keyed and legacy array). After it runs, every active dataset has a matching nemar_catalog row and the discover card reads consistent data.Idempotent (
INSERT OR IGNOREno-ops on a fully-populated catalog).Verification
Pre-migration:
SELECT COUNT(*) FROM datasets d LEFT JOIN nemar_catalog c ON c.id = d.dataset_id WHERE c.id IS NULL AND d.status = 'active'→ 103 missing.Post-migration (expected):
0 missing. Live verify will assert nm000166's catalog row exists and has authors/modalities/etc. populated.Follow-up tracked separately
The root architectural issue —
catalog-sync.tsdepends on legacy nemar.org as its source — should be addressed by an in-process catalog generator that buildsnemar_catalogfromdatasets+enrichment_jsondirectly. Without that, the same gap will recur for every dataset created via the new pipeline that hasn't reached the legacy nemar.org datapipeline. I'll file a tracking issue.