Skip to content

Conversation

anettkva
Copy link
Member

Summary

Adds the seed script, which loads the catalog from data/ into the database and fills the search tables. Run it with npm run db:seed.

What it does

  • Loads apparatus, element groups, variant groups, elements and vaults from data/*.json, and converts them to the new shape (variant groups as a column, apparatus sort order)
  • Checks the data first. If something breaks a rule in DATA_MODEL.md, it stops with a clear message and changes nothing
  • Writes everything in one transaction, so a failed run changes nothing, and a second run with the same data changes nothing either
  • Never touches user data (coaches, gymnasts, routines and their lists)
  • Rebuilds the search tables CatalogEntry and CatalogWord on every run
  • Prints a table of what was inserted, updated, marked as removed and deleted

Decisions

  • Abbreviations are written out as search words. For example, hstd also gives handstand, and LB gives low bar. The list was reviewed by the team: fwd, bwd, swd, hstd, hdst, HB, LB, sec. and min.. etc. is left out on purpose. A test fails if the data contains an abbreviation that is in neither list.
  • The same word rules for the seed and the search. normalizeWords in backend/src/catalog/words.ts lowercases, removes accents and keeps codes like 3.304 whole. The search in Add indexes and search #24 must use it too.
  • Removed elements are kept while they are in use. An element missing from data/ gets removedAt. It is deleted only if no routine or gymnast list uses it, and removedAt is cleared if it comes back.
  • One search entry per code, from the first variant that is not removed. Its words come from all variants that are not removed.
  • Rows with ids starting with SYN- are ignored. They are synthetic test data from another script.
  • 749 elements, not 753. That is what data/ contains after the corrections in the extraction work.

How to test

  1. Run npm ci, then npm run db:migrate, from the root
  2. Run npm run db:seed twice. The second run should show only zeros
  3. Run the tests with npm test

Look at the data in the browser

  1. Run npm run db:studio from the root
  2. Open the address the terminal prints, for example http://localhost:51212. The port can change between runs
  3. Click a table, for example Element or CatalogWord, to see the rows
  4. Stop it with Ctrl+C

If a table says "No data", check that Studio is still running and reload the page. Changes you make to the catalog in Studio are overwritten by the next seed.

The README has the same steps under "Database (local setup)", in "6. Seeding" and "7. Look at the data".

Closes #23

🤖 Generated with Claude Code

@anettkva anettkva requested a review from a team as a code owner October 15, 2026 18:15
Copy link
Member

@ronjalh ronjalh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@ronjalh ronjalh merged commit a77eb29 into dev Oct 15, 2026
@ronjalh ronjalh deleted the 23-seed-the-catalog branch October 15, 2026 19:22
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants