Skip to content

Commit f596517

Browse files
committed
docs(spec): drop the stale "fields every load can fill" advice for seed keys
Seat S2: since #34854 a composite-key row whose reference the first load leaves empty is found again by its authored key and filled later, so the advice to key only on fields every load can fill is false. Dropped from the migration entry replacement and SEED_MODE_RETIRED_FIX; seed-data.mdx step 2 now says what the loader does. N12: the changeset states the rule count 70 to 69. Text only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX
1 parent 09901d0 commit f596517

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎.changeset/34613-seed-mode-insert-replace-retired.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ What moves (each line FROM → TO):
2424
- a stored dataset that still declares one, replayed by the boot seed, the per-organization replay, the dev hot reload or a package install, upgrade or sample-data reseed (`SeedLoaderService.loadStored`, `@objectstack/metadata-protocol`): FROM inserted again on every load TO refused alone — it writes nothing, the load result carries one error with the prescription and `success: false`, and every other dataset loads. `SeedLoaderService.load()` and `validate()` refuse the dataset the same way when handed one unparsed, so a dry run reports what a real load does.
2525
- a compiled artifact (`objectstack.json`) carrying such a dataset, booted by `os serve` / `os start` / `os dev` (the artifact door, `MetadataPlugin`, `@objectstack/metadata`): the door parses the artifact without that dataset and hands it back to the seed load, which refuses it alone; the door logs a warning naming the dataset and the fix. Everything else in the artifact registers and boots.
2626
- `os diff` (`@objectstack/cli`) on a dataset declaring either mode: FROM "a replay inserts these again" TO a note that the mode is retired, that a replay refuses the dataset, and what to declare.
27-
- the advisory lint rule `seed-insert-mode-duplicates-on-replay` (`validateSeedReplaySafety`, `@objectstack/lint`): FROM a warning on `mode: 'insert'` TO removed; the schema refusal does its job for both modes.
27+
- the advisory lint rule `seed-insert-mode-duplicates-on-replay` (`validateSeedReplaySafety`, `@objectstack/lint`): FROM a warning on `mode: 'insert'` TO removed; the schema refusal does its job for both modes. The author-time rule count `os validate` / `os build` print goes from 70 to 69.
2828
- the save door's and the loader's hint for a key no record carries: FROM "or use mode 'insert' for rows with no natural key" TO a list of fields when no single field names a row, or `'id'` when the records carry their own ids.
2929

3030
The fix: declare which field identifies a row and drop the mode (or declare `upsert` for reference data the package keeps current). Set `externalId` to the field that names a row, to a list of fields when no single field does (a junction table's `['team', 'project']`), or to `'id'` when the records carry their own ids. Rebuild the package, and reinstall it where it was installed with `os package install`, so the stored body carries the new declaration.

‎content/docs/data-modeling/seed-data.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ To convert a dataset, declare which field identifies a row, then drop the mode
156156
1. **A field names the row** (a code, a slug, an email): set `externalId` to it.
157157
2. **No single field does** (a join table, a line item under a parent): set
158158
`externalId` to the list of fields that together identify a row, for example
159-
`['team', 'project']`. Reference fields are matched by their resolved ids, so
160-
list only fields every load can fill: a reference the first load has to leave
161-
empty (a person who has not signed up yet) makes each later load miss that row
162-
and insert another. See
159+
`['team', 'project']`. Reference fields are matched by their resolved ids. A
160+
reference the first load has to leave empty (a person who has not signed up
161+
yet) still belongs in the key: each later load finds that row again by the
162+
key as authored, and the load that can resolve the person fills it in. See
163163
[Composite natural key](#composite-externalid--join--junction-tables).
164164
3. **The records carry their own ids**: set `externalId: 'id'`.
165165

‎packages/spec/src/data/seed.zod.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
const SEED_MODE_RETIRED_FIX =
2929
'Declare the rows\' identity instead: keep the default `mode: \'ignore\'` (or `\'upsert\'`) and set '
3030
+ '`externalId` to the field that names a row, to a list of fields when no single field does (a junction '
31-
+ 'table\'s `[\'team\', \'project\']`, listing only fields every load can fill), or to `\'id\'` when the '
31+
+ 'table\'s `[\'team\', \'project\']`), or to `\'id\'` when the '
3232
+ 'records carry their own ids.';
3333

3434
/**

‎packages/spec/src/migrations/entries/semantic/18.seed-mode-insert-replace-retired.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export const entry: SemanticMigration = {
1515
replacement:
1616
'Keep the default `mode: \'ignore\'` (or declare `\'upsert\'` for reference data the package keeps current) and '
1717
+ 'set `externalId` to the field that names a row, to a list of fields when no single field does (a junction '
18-
+ 'table\'s `[\'team\', \'project\']`; list only fields every load can fill, since a reference the first '
19-
+ 'load leaves empty makes each later load miss that row), or to `\'id\'` when the records carry their own ids',
18+
+ 'table\'s `[\'team\', \'project\']`), or to `\'id\'` when the records carry their own ids',
2019
reason:
2120
'A seed is replayed, not applied once: on every single-tenant boot, every package install or upgrade, every '
2221
+ 'publish. `insert` matched no existing row, so every replay inserted each record again, and `replace` did the '

0 commit comments

Comments
 (0)