Skip to content

Catalog search schema: library_track_index, library_track_data, label and alternate-name trigram indexes (BS#3740) - #3771

Merged
jakebromberg merged 2 commits into
mainfrom
orchestrator/migration-catalog-search-schema-library-track-inde
Nov 5, 2026
Merged

jakebromberg merged 2 commits into
mainfrom
orchestrator/migration-catalog-search-schema-library-track-inde

Conversation

@jakebromberg

Copy link
Copy Markdown
Member

Closes #3740

Step 3 of #3738. Adds the catalog search schema as migration 0209_catalog-search-schema. Nothing reads or writes the new tables yet.

What changed

  • library_track_index (library_id integer PK, FK library.id ON DELETE CASCADE; search_doc tsvector) with a GIN index on search_doc. This is the narrow table the matcher reads.
  • library_track_data (library_id PK, same FK; source, source_batch, discogs_release_id, tracks jsonb, fingerprint, refreshed_at). A record has a row in both tables or in neither. This follows the 2026-11-04 plan-revision comment on Migration: catalog search schema (library_track_index table, label and alternate-name trigram indexes) #3740, which supersedes the single-table design in the issue body.
  • Trigram GIN indexes library_label_trgm_idx and library_alternate_artist_name_trgm_idx on library. They are created with a hand-added IF NOT EXISTS, and the migration header carries the exact CREATE INDEX CONCURRENTLY commands for the production pre-build (per docs/migrations.md). The new tables' own indexes are plain, since the tables are empty.
  • tests/mocks/database.mock.ts gets doubles for both tables, as check:db-mock-sync requires.

label stays out of search_doc, no tracks column is added to library, and the 500-character title cap is left to the future writer job. Ops builds the two trigram indexes on production before this merges; no production command was run from this PR.

Size: about 46 added lines of production source in schema.ts (much of it comments); the rest is the generated migration and snapshot, tests, and the mock.

Acceptance criteria and how each is tested

  • Migration applies cleanly, header holds the CONCURRENTLY commands: applied through dev_env/init-db.mjs (the same runner CI and deploy use) against a fresh Postgres; npm run lint:migrations passes with 0 warnings.
  • GIN index on library_track_index.search_doc and both trigram indexes exist after a fresh migrate: tests/integration/library-track-index-schema.spec.js checks each is a valid gin index on the expected column.
  • The foreign keys cascade on delete: same spec inserts a library row plus a row in each new table, deletes the library row, and asserts both are gone. It also asserts that an orphan library_id is rejected (23503) on both tables.
  • npm run ci:testmock: not run. Docker was not running on the machine and starting Docker Desktop would take over the screen. Instead I ran the integration spec against a private Homebrew PostgreSQL 18 cluster (migrated and seeded via dev_env/init-db.mjs). The repo's other local checks pass: typecheck, format:check, lint:changed (0 errors), check:db-mock-sync, lint:migrations, and the unit suite (761 suites, 16534 tests). Please let CI's integration job confirm.

Mutation check: dropping the two indexes and replacing one cascade FK with a plain FK makes three of the six cases fail. I did not mutate the orphan-rejection cases (they pass on any FK), and did not mutate library_alternate_artist_name_trgm_idx separately; it uses the same assertion path as the label index.

Mirrors: tests/mocks/database.mock.ts (hand-maintained double, enforced by check:db-mock-sync); meta/applied-hashes.json and the journal were updated by the repo's scripts.

…brary.label and alternate_artist_name (BS#3740)

Migration 0209 adds the narrow library_track_index table (search_doc tsvector with a GIN index) and its sibling library_track_data, both keyed by library_id with ON DELETE CASCADE, plus trigram GIN indexes on library.label and library.alternate_artist_name. The trigram indexes use IF NOT EXISTS and the header carries the CREATE INDEX CONCURRENTLY commands for the production pre-build. Nothing reads or writes the new tables yet.
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Schema constraint shape report

Probed: automated prod RDS snapshot 2026-11-04T05:04:37.447000+00:00, restored to ephemeral sandbox for run 41954231923 (schema wxyc_schema), before the pending migrations were applied.

This PR adds:

  • could not derive SELECT — CHECK (source IN ('compilation', 'override', 'album_metadata')) (library_track_data_source_check)
  • query failed: relation "wxyc_schema.library_track_data" does not exist — FOREIGN KEY (library_id) REFERENCES library(id) on library_track_data
  • query failed: relation "wxyc_schema.library_track_index" does not exist — FOREIGN KEY (library_id) REFERENCES library(id) on library_track_index

one or more probes failed; see above. The check status is non-blocking.

…ber dedup merge, CHECK library_track_data.source, and pin the full index definitions (BS#3740)

Both new tables carry an ON DELETE CASCADE FK into library.id, so the dedup job has to repoint them before it deletes a loser: FK_TARGETS entries keyed on library_id alone (the survivor's row wins, else the loser's row moves), the EXPECTED delete-rule map, the README table, and an integration test of both outcomes. library_track_data.source is limited to compilation, override and album_metadata by a CHECK; migration 0209 is regenerated with the same number. The schema spec now asserts the exact CREATE INDEX definitions, including gin_trgm_ops, and the CHECK.
@jakebromberg
jakebromberg merged commit cc3c295 into main Nov 5, 2026
7 checks passed
@jakebromberg
jakebromberg deleted the orchestrator/migration-catalog-search-schema-library-track-inde branch November 5, 2026 02:34
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.

Migration: catalog search schema (library_track_index table, label and alternate-name trigram indexes)

1 participant