Add a guide to updating data that isn't in the database
docs/updating-data-in-code.md covers content that lives in code rather than SQLite and how to change it: - The two kinds of admin dropdown: filled from records (optionsFrom, change the record) and fixed lists (options, in adminSchema.ts), and that a bare-string option shows its stored value while a [value, label] pair shows the label. - Relabelling a dropdown is adminSchema.ts alone; adding, removing or renaming a stored value is a migration, both descriptor halves and whatever the public site renders it with. - A table of every dropdown in the editor, where its values and labels live, and what on the public site depends on them. - The front page's three kinds of "section name" (the heading the admin sets, the dropdown label, the subnav link) and stat sources. - Every other piece of code-owned content: nav, page section manifests, banner, history decades, map grid, feedback types, public label maps, roles, SITE_ORIGIN. CLAUDE.md points at it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7eeac6b22f
commit
e35d09b172
2 changed files with 297 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu
|
|||
- `src/data/` holds only hardcoded data shared across multiple section files (e.g. `historyDecades.ts`, map grid). Everything else comes from SQLite.
|
||||
- `navConfig.ts` is the single source of truth for navigation, routes, and actions (header, footer, pages).
|
||||
- `api.ts` is the shared caching client used by frontend data hooks.
|
||||
- `docs/updating-data-in-code.md`: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content.
|
||||
- Logos: org logos in `public/org-logos/` (served at `/org-logos/`), event logos in `public/event-logos/`. The `<Logo>` component hides itself on load error.
|
||||
|
||||
## Rules and gotchas
|
||||
|
|
|
|||
296
docs/updating-data-in-code.md
Normal file
296
docs/updating-data-in-code.md
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
# Updating data that isn't in the database
|
||||
|
||||
Most of the site's content lives in SQLite and is edited in the admin
|
||||
(`/admin`). Some of it deliberately lives in code instead: labels,
|
||||
navigation, fixed lists, and a few pieces of editorial copy. Changing
|
||||
those means editing a file, committing it on a branch, and deploying.
|
||||
|
||||
This guide covers where each of those lives and how to change it
|
||||
safely, starting with the question that comes up most: how to change
|
||||
what a dropdown in the admin editor says.
|
||||
|
||||
- [Database or code?](#database-or-code)
|
||||
- [Admin dropdowns](#admin-dropdowns)
|
||||
- [Two kinds of dropdown](#two-kinds-of-dropdown)
|
||||
- [Renaming what a dropdown shows](#renaming-what-a-dropdown-shows)
|
||||
- [Adding, removing or renaming a stored value](#adding-removing-or-renaming-a-stored-value)
|
||||
- [Every dropdown in the editor](#every-dropdown-in-the-editor)
|
||||
- [Front page section names](#front-page-section-names)
|
||||
- [Front page stat sources](#front-page-stat-sources)
|
||||
- [Other content that lives in code](#other-content-that-lives-in-code)
|
||||
- [Making the change](#making-the-change)
|
||||
|
||||
---
|
||||
|
||||
## Database or code?
|
||||
|
||||
| If it's… | It lives in… | Change it by… |
|
||||
| ------------------------------------------------------------ | ---------------- | ------------------------------------ |
|
||||
| A record: an event, organization, person, team, award, timeline entry | the database | editing it in the admin |
|
||||
| The front page's words, photos, bands, stats and paths | the database | Admin → Front page |
|
||||
| The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) |
|
||||
| The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) |
|
||||
| Navigation, page section titles, colours, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) |
|
||||
|
||||
The rule of thumb from `CLAUDE.md`: data belongs in the database,
|
||||
presentation belongs in code. A dropdown's *values* are data the
|
||||
database enforces; its *labels* are presentation.
|
||||
|
||||
---
|
||||
|
||||
## Admin dropdowns
|
||||
|
||||
The admin editor is generated from two descriptor files that describe
|
||||
each entity:
|
||||
|
||||
| File | What it holds |
|
||||
| ----------------------------- | ----------------------------------------------------- |
|
||||
| `src/lib/adminSchema.ts` | The **form**: field labels, help text, dropdown labels, list columns and filters |
|
||||
| `server/src/admin-schema.js` | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` |
|
||||
|
||||
And the database itself holds the final word: most fixed lists are a
|
||||
`CHECK (... IN (...))` constraint on the column (read them in
|
||||
`server/src/migrations/023_schema.sql` and any later migration).
|
||||
|
||||
### Two kinds of dropdown
|
||||
|
||||
Every dropdown in the editor is one of these:
|
||||
|
||||
**1. Filled from records (`optionsFrom`).** The choices are rows in the
|
||||
database: organizations, people, events, teams, awards, event scopes,
|
||||
regions. The label is the record's own name. To change what one of
|
||||
these shows, **edit the record in the admin**; there's nothing to
|
||||
change in code. Adding a person adds them to every "Person" dropdown.
|
||||
|
||||
The queries behind them are `OPTION_QUERIES` in
|
||||
`server/src/admin-schema.js`. Edit a query only to change *which*
|
||||
records appear or their order, e.g. to put a disambiguating
|
||||
organization name in the label, as the `awards` query does.
|
||||
|
||||
> Event scopes (National, Regional, Local…) are records in the
|
||||
> `event_scopes` table, but there's no admin page for them. Their names
|
||||
> are changed with a migration: `UPDATE event_scopes SET name = '…' WHERE id = '…';`
|
||||
|
||||
**2. A fixed list in code (`options`).** The choices are written in
|
||||
`src/lib/adminSchema.ts`. Each option is one of two shapes:
|
||||
|
||||
```ts
|
||||
options: ["speaker", "leader", "host"] // shows: speaker, leader, host
|
||||
options: [["speaker", "Speaker"], ["leader", "Leader"]] // shows: Speaker, Leader
|
||||
```
|
||||
|
||||
A bare string is shown exactly as stored. A `[value, label]` pair
|
||||
stores the first and shows the second. That difference is what makes
|
||||
relabelling cheap.
|
||||
|
||||
### Renaming what a dropdown shows
|
||||
|
||||
If the stored value stays the same and you only want the dropdown to
|
||||
read differently, **only `src/lib/adminSchema.ts` changes**. No
|
||||
migration, no server change, and every existing row keeps working.
|
||||
|
||||
Find the field (search for its column name) and give the option a
|
||||
label. For example, to make the event-people Role dropdown read nicely:
|
||||
|
||||
```ts
|
||||
// before
|
||||
options: ["speaker", "leader", "facilitator", "host", "musician", "volunteer", "attendee"],
|
||||
|
||||
// after — values unchanged, labels added
|
||||
options: [
|
||||
["speaker", "Speaker"],
|
||||
["leader", "Leader"],
|
||||
["facilitator", "Facilitator"],
|
||||
["host", "Host"],
|
||||
["musician", "Musician"],
|
||||
["volunteer", "Volunteer"],
|
||||
["attendee", "Attendee (not shown publicly)"],
|
||||
],
|
||||
```
|
||||
|
||||
Things to check while you're there:
|
||||
|
||||
- **The same list often appears twice**: once on the form field and
|
||||
once in the entity's `list.filters` (the dropdowns above the list
|
||||
view). Relabel both so they agree.
|
||||
- **Several lists are shared constants.** Front page sections and stat
|
||||
sources are `FRONT_PAGE_SECTIONS` and `STAT_SOURCES` near the top of
|
||||
the front page block; change them there, once.
|
||||
- **`blankLabel`** is the text of the empty first option
|
||||
(`"— brand —"`, `"— choose —"`). It's also just a label.
|
||||
- The value (first item) **must not change**. It's what's stored in
|
||||
the database and what the server and the CHECK constraint compare
|
||||
against.
|
||||
|
||||
### Adding, removing or renaming a stored value
|
||||
|
||||
This changes what the database will accept, so four places move
|
||||
together, in one branch:
|
||||
|
||||
1. **A new migration** (`server/src/migrations/0NN_description.sql`)
|
||||
that changes the column's CHECK. A CHECK can't be altered in place,
|
||||
so either:
|
||||
- add a new column with the new CHECK, copy the data across, and
|
||||
drop the old one (see `025_hero_backdrop_feature.sql`), or
|
||||
- rebuild the table (see `024_front_page_video.sql`, and the
|
||||
rebuild notes in `CLAUDE.md` under Migrations).
|
||||
|
||||
**Renaming** a value also needs an `UPDATE` in the same migration so
|
||||
existing rows move to the new value. **Removing** one needs you to
|
||||
decide what existing rows become first.
|
||||
2. **`server/src/admin-schema.js`**: the `enumeration("column", [...])`
|
||||
list for that column.
|
||||
3. **`src/lib/adminSchema.ts`**: the `options` on the form field, and on
|
||||
the list filter if there is one.
|
||||
4. **Anywhere the public site renders or relies on the value**, listed in
|
||||
the table below (for example `EVENT_TYPES` for event types, or the
|
||||
`SECTIONS` map in `Home.tsx` for front page sections).
|
||||
|
||||
If the server descriptor and the database disagree, the API refuses to
|
||||
start: `admin-schema-sync.js` compares them at boot and throws with a
|
||||
message naming the column. That's deliberate. Fix whichever side is
|
||||
wrong rather than working around it.
|
||||
|
||||
### Every dropdown in the editor
|
||||
|
||||
**Fixed lists** (`options`: labels in `src/lib/adminSchema.ts`, values
|
||||
also in `admin-schema.js` and a CHECK):
|
||||
|
||||
| Entity → field | Stored values | Labelled? | Also used on the public site by |
|
||||
| --- | --- | --- | --- |
|
||||
| Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_KIND_LABEL` in `src/lib/hrefs.ts`, and the route each kind uses |
|
||||
| Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it |
|
||||
| Organizations → Region areas → Edge | top, bottom | no | the chapter map (`OrgList-Map.tsx`) |
|
||||
| Events → Type (+ list filter) | retreat, class, workshop, meeting, other | no | `EVENT_TYPES` in `src/lib/eventTypes.ts` (public labels and plurals) |
|
||||
| Events → Status (+ list filter) | upcoming, past, cancelled | no | `STATUS_LABEL` in `src/pages/EventDetail.tsx` |
|
||||
| Events → Series → Repeats | weekly, monthly_date, monthly_weekday | **yes** | `src/lib/eventSeries.ts` |
|
||||
| Events → People → Role | speaker, leader, facilitator, host, musician, volunteer, attendee | no | `ROLE_LABEL` in `src/pages/EventDetail.tsx` |
|
||||
| People → Affiliations → Role; Teams → Members → Role | lead, board, staff, volunteer, member | no | `ROLE_LABEL` in `src/pages/PersonDetail.tsx` |
|
||||
| Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` |
|
||||
| Content blocks → Slot | card, body | no | `ContentBlocks.tsx` |
|
||||
| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider | no | `ContentBlocks.tsx` (one renderer per type) |
|
||||
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
|
||||
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
|
||||
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
|
||||
| Front page → Background | brand, photos | **yes** | `HeroStage.tsx` |
|
||||
| Front page → Beside the words | none, livestream, video | **yes** | `HeroStage.tsx` |
|
||||
| Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect | **yes**, `FRONT_PAGE_SECTIONS` | `SECTIONS` in `src/pages/Home.tsx`; see [below](#front-page-section-names) |
|
||||
| Front page → Stats → Where it comes from | manual, years_since, regions, … | **yes**, `STAT_SOURCES` | `STAT_QUERIES` in `server/src/routes/home.js`; see [below](#front-page-stat-sources) |
|
||||
| Every list → Published / Featured filter | 1, 0 | **yes** | n/a |
|
||||
|
||||
"No, shows values" means the dropdown currently shows the raw value,
|
||||
so relabelling it is just [adding labels](#renaming-what-a-dropdown-shows).
|
||||
|
||||
**Lists filled from records** (`optionsFrom`: edit the records, not
|
||||
code):
|
||||
|
||||
| Dropdown | `optionsFrom` | Comes from |
|
||||
| --- | --- | --- |
|
||||
| Chapter → Region | `regions` | organizations of kind region |
|
||||
| Event → Scope (+ list filter) | `event_scopes` | the `event_scopes` table (migration only) |
|
||||
| Event hosts → Organization; affiliations; team and award "Organization" / "Awarded by"; person → Home organization | `organizations` | organizations, labelled by name |
|
||||
| Event hosts / event people / team members / timeline people → Person | `people` | people |
|
||||
| Affiliations → Team | `teams` | teams, filtered to the chosen organization |
|
||||
| Person awards → Award | `awards` | awards, labelled "Award — Organization" |
|
||||
| Person awards → Presented at; Front page → Count down to | `events` | events |
|
||||
| Timeline → Record | `timeline_refs` | all five kinds, filtered by "Points at" |
|
||||
|
||||
---
|
||||
|
||||
## Front page section names
|
||||
|
||||
"Section name" means three different things on the front page, and
|
||||
each is changed in a different place:
|
||||
|
||||
| What you see | Where it's set |
|
||||
| --- | --- |
|
||||
| **The heading on the page** ("National Retreats", "What's on") | **Admin → Front page → Page sections → Heading.** Blank uses the default below. |
|
||||
| The default heading when that field is blank | `SECTIONS` in `src/pages/Home.tsx`, the `title` of each entry |
|
||||
| **The name in the admin's Section dropdown** ("National Retreats carousel") | `FRONT_PAGE_SECTIONS` in `src/lib/adminSchema.ts` |
|
||||
| The subnav links under the header ("#Retreats", "#Calendar") | `PAGE_SECTIONS["/"]` in `src/navConfig.ts` |
|
||||
|
||||
To rename a band **for visitors**, use the admin. To rename how it
|
||||
reads **in the editor's dropdown**, edit `FRONT_PAGE_SECTIONS`:
|
||||
|
||||
```ts
|
||||
const FRONT_PAGE_SECTIONS = [
|
||||
["countdown", "Countdown to the next event"],
|
||||
["retreats", "National Retreats carousel"], // ← the right-hand side is the label
|
||||
["calendar", "Event calendar"],
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
The subnav links jump to each band by its anchor: the `id` passed in
|
||||
each band's `render` in `Home.tsx` (`#retreats`, `#calendar`,
|
||||
`#numbers`, `#connect`, and `#hero` for the hero). If you rename a
|
||||
subnav label in `navConfig.ts`, leave its `hash` alone unless you also
|
||||
change the band's `id`.
|
||||
|
||||
**Adding a new kind of band** (not just renaming one) is a feature,
|
||||
not a relabel: it needs a component, an entry in `SECTIONS` in
|
||||
`Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the
|
||||
`enumeration("section", …)` in `server/src/admin-schema.js`, to the
|
||||
`FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the
|
||||
CHECK on `front_page_sections.section` via a migration.
|
||||
|
||||
---
|
||||
|
||||
## Front page stat sources
|
||||
|
||||
The numbers band's "Where it comes from" dropdown works the same way:
|
||||
|
||||
- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema.ts`.
|
||||
- **Change what a count counts:** its query in `STAT_QUERIES` in
|
||||
`server/src/routes/home.js`. Keep it counting exactly what the
|
||||
matching public page shows (published rows), or the number and the
|
||||
page will disagree.
|
||||
- **Add a source:** the CHECK on `front_page_stats.source` (migration),
|
||||
the `enumeration("source", …)` in `server/src/admin-schema.js`,
|
||||
`STAT_SOURCES`, and a query in `STAT_QUERIES`.
|
||||
|
||||
---
|
||||
|
||||
## Other content that lives in code
|
||||
|
||||
| What | File | Notes |
|
||||
| --- | --- | --- |
|
||||
| Header and footer navigation, page subnav links | `src/navConfig.ts` | `PAGE_LINKS`, `PAGE_SECTIONS`, `NAV_ACTIONS`. A new page also needs a route in `src/App.tsx`. |
|
||||
| Section titles, blurbs and colours on Retreats, Community, Leadership, Resources, Feedback, Privacy, Terms | the page file in `src/pages/` | the `SECTIONS` array at the top. A section's `id` must match its subnav `hash`. |
|
||||
| Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. |
|
||||
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
|
||||
| Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Organizations → a region → Map areas). |
|
||||
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. |
|
||||
| Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. |
|
||||
| Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | |
|
||||
| Organization kind labels ("Region", "Chapter") | `ORG_KIND_LABEL` in `src/lib/hrefs.ts` | |
|
||||
| Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. |
|
||||
| Admin navigation | `src/pages/admin/adminNav.ts` | |
|
||||
| The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | |
|
||||
| Version shown on the admin home page | `src/lib/version.ts` | |
|
||||
| Image directories (where logos and photos are looked up) | `src/lib/media.ts` | |
|
||||
|
||||
---
|
||||
|
||||
## Making the change
|
||||
|
||||
1. Branch from `main` (never commit to `main` directly).
|
||||
2. Edit the file(s). For a stored-value change, write the migration as
|
||||
well, numbered after the last one in `server/src/migrations/`.
|
||||
3. Check it:
|
||||
```sh
|
||||
pnpm exec tsc # type-check
|
||||
pnpm build # the site still builds
|
||||
```
|
||||
For anything touching the server or a migration, also run it
|
||||
locally against a scratch database:
|
||||
```sh
|
||||
cd server
|
||||
DB_PATH=./dev.db pnpm migrate
|
||||
DB_PATH=./dev.db pnpm dev # boot fails loudly if a descriptor and the schema disagree
|
||||
```
|
||||
and open the admin editor to see the dropdown.
|
||||
4. Commit, push the branch, and open a pull request with `tea`.
|
||||
5. After it's merged, deploy. A migration runs automatically when the
|
||||
`ngu-api` service restarts; back up `/var/lib/ngu/ngu.db` first if
|
||||
the change includes one.
|
||||
Loading…
Add table
Add a link
Reference in a new issue