You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2e07e61
Browse filesBrowse the repository at this point in the historyBrowse files
docs: document the unit-code backfill door (os migrate unit-codes and its REST twin) (#37378)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg8ZBQe4UHadd2fGHGeWRW9V)_
repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS
Fixes#35868
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:运维与租户管理员在文档站能读到「把已存的自由文本单位换成单位代码」的命令与接口说明,并新增一页「计量单位」;功能本身不变。
- 为什么做:单位保存被拒时提示里点名的修复命令,文档此前只字未提;属于计量单位(单位代码)这条线的文档补齐。
- 出错会怎样:只影响文档与一段配置项说明文字,写错只会误导读者,可随时撤回。
- 要你做什么:无。
## What changes
- `content/docs/deployment/cli.mdx`: a row for `os migrate unit-codes`
in the `os migrate` table, and a new `os migrate unit-codes` section
beside `os migrate record-currency-codes` — dry-run (no mapping, then
with mapping) and apply examples, the mapping file shape with the `""`
entry for a blank unit beside a quantity, the `--org` /
`--all-organizations` scope rule, what is never rewritten, and the REST
twin `POST /api/v1/meta/_migrate-unit-codes` (body, preview posture,
403s, the maintenance switch). Every claim measured against
`packages/cli/src/commands/migrate/unit-codes.ts`,
`packages/objectql/src/unit-code-backfill.ts` and
`packages/rest/src/meta-unit-code-backfill-route.ts` at 98bda0a.
- `content/docs/data-modeling/units.mdx` (new, listed in `meta.json`
after `currency` and in the section's landing index): the three
`unitConfig` modes, and "Converting a field that already holds rows" —
the two 409 findings, the dry run, the mapping, `--apply` — linking the
CLI section. Overlap check (A3): no data-modeling page explained units
or `unitConfig` (`field-types.mdx`, `fields.mdx`,
`field-type-decision-tree.mdx`: zero `unitConfig` hits), so a new page
beside `currency.mdx`.
- `packages/spec/src/api/rest-server.zod.ts`: the
`metadata.endpoints.maintenance` describe names `POST
/meta/_migrate-unit-codes` beside the currency door (the route already
registers behind that switch, and `rest-config-mount-table.pin.test.ts`
already pins it). `content/docs/references/api/rest-server.mdx`
regenerated by `check:generated --fix` (only `check:docs` was stale).
Patch changeset for `@objectstack/spec`.
## Acceptance notes
- The card names the findings `unit_mode_to_record` and
`unit_mode_to_code`; main raises `unit_mode_to_record` and
`unit_code_field_declared`
(`packages/metadata-protocol/src/protocol-write-face.ts`). The docs
follow the code.
- No SDK method exists for the unit door (no `migrateUnitCodes` in
`packages/client/src`), so unlike the currency section there is no SDK
example.
- **Open fence item:** adding the page makes `pnpm
check:docs-audit-scope` red: `scripts/docs-audit/handwritten-docs.json`
must list `content/docs/data-modeling/units.mdx` (one generated line,
`node scripts/docs-audit/check-audit-scope.mjs --write`). That path is
outside the claim's file surface, so it is not in this PR; it waits for
the seat's word.
## Tests
<details><summary>Local runs at 9ec53fc</summary>
- `pnpm --filter @objectstack/spec build` → VERDICT command-exit 0
- `pnpm --filter @objectstack/spec check:generated` → 1 of 14 stale
(`check:docs`), fixed with `--fix`, rest-server.mdx 1 line
- `pnpm --filter @objectstack/spec typecheck` + `vitest run
src/api/rest-server.test.ts` → Test Files 1 passed, Tests 53 passed
- `dispatch-gates --commands` derived 104 families; all run; `--ran`
reconciliation 104/104. Red: `check:docs-audit-scope` (the fence item
above). Not measured locally (exit 3, prerequisite: whole-workspace
build): `check:dual-build-cjs-loads`, `check:lean-entry-closure`,
`check:skill-examples`, `check-plugin-teardown-shape --self-test`
(shallow clone) — CI runs them. After building the lint closure:
`check:doc-formula-expressions`, `check:doc-security-posture`,
`check:docs-transcript-drift` exit 0.
- `overlap-check --branch=HEAD` → clean against origin/main and #37314.
</details>
## Verification
Read first: `content/docs/deployment/cli.mdx` (the new section; risk: a
claim that drifts from the command),
`content/docs/data-modeling/units.mdx`.
Two-minute check: `git grep -n "_migrate-unit-codes" --
packages/spec/src/api/rest-server.zod.ts content/docs` shows the
describe, its reference row, the CLI section and the units page.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CbdHk3orAeensH6EzS)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CbdHk3orAeensH6EzS -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
docs(spec): the `metadata.endpoints.maintenance` describe names the unit code backfill door `POST /meta/_migrate-unit-codes` beside the record-currency one, which the switch already mounts and removes
Copy file name to clipboardExpand all lines: content/docs/data-modeling/index.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ That one definition is enough to get a persisted table, CRUD + query endpoints,
50
50
<Cardhref="/docs/data-modeling/field-types"title="Field Types"description="Gallery of every field type with examples" />
51
51
<Cardhref="/docs/data-modeling/field-type-decision-tree"title="Field Type Decision Tree"description="Choosing the right field type: flowchart, quick-reference table, and use cases" />
52
52
<Cardhref="/docs/data-modeling/currency"title="Currency"description="Dynamic, fixed and record currency modes, and what a record-currency amount refuses" />
53
+
<Cardhref="/docs/data-modeling/units"title="Units"description="Fixed, record and code unit modes, and converting the free text a field stored before it held unit codes" />
53
54
<Cardhref="/docs/data-modeling/relationships"title="Relationships & Lookups"description="Lookup, master-detail, and cross-object modeling" />
54
55
<Cardhref="/docs/data-modeling/object-extensions"title="Object Extensions"description="Add fields, validations, and indexes to an object another package owns" />
55
56
<Cardhref="/docs/data-modeling/validation"title="Validation"description="Validation metadata and CEL rule authoring" />
title: Units of measure — fixed, record and code modes
3
+
navTitle: Units
4
+
description: How a quantity gets its unit — one standard code, or each record's own unit code in a sibling text field — how a text field declares itself a unit code field, and how to convert the free text a field stored before it held unit codes
5
+
---
6
+
7
+
A quantity is a `number` field that stores a **bare number**, never a `{ value, unit }`
8
+
object. What the field's `unitConfig` decides is which unit that number is in. A unit is
9
+
stored as a **code**, in exact uppercase, never as a record id: a standard UN/ECE
10
+
Recommendation 20 code such as `KGM` (kilogram), `MTR` (metre) or `H87` (piece), or one
11
+
of the organization's own units (ADR-0158). The keys mirror
12
+
[`currencyConfig`](/docs/data-modeling/currency): `unitConfig`, `unitMode` and `unitField`
13
+
mean what `currencyConfig`, `currencyMode` and `currencyField` mean there.
14
+
15
+
## The three modes
16
+
17
+
`unitMode` is required and has no default: the platform never guesses a unit.
18
+
19
+
| Mode | On | Declares | The unit of each record |
20
+
|:---|:---|:---|:---|
21
+
|`fixed`|`number`|`unit`: one standard code, checked at build | always `unit`|
22
+
|`record`|`number`|`unitField`: the sibling `text` field holding each record's code; optional `unitDimension`| whatever that record's `unitField` holds |
23
+
|`code`|`text`| optional `unitDimension`| the field holds the unit code itself, with no quantity beside it |
Copy file name to clipboardExpand all lines: content/docs/deployment/cli.mdx
+96Lines changed: 96 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1539,6 +1539,7 @@ where the data lives.
1539
1539
| `os migrate option-codes` | Rewrite option values still stored as a number, a boolean or SQLite `"N.0"` text (rows written before option fields stored the code string) to that code string, so filters, reads and unique keys see one value. Values it cannot decide are listed, never rewritten. No flag; idempotent. See [below](#os-migrate-option-codes) |
1540
1540
| `os migrate text-scalars` | Rewrite numbers and booleans still stored raw on text fields (rows written before text fields stored the string) to that string, so filters, reads and unique keys see one value. SQLite `"N.0"` text it cannot decide is listed, never rewritten. No flag; idempotent. See [below](#os-migrate-text-scalars) |
1541
1541
| `os migrate record-currency-codes` | Write the currency code you give into the rows of a record-mode currency field that hold an amount and no code, the rows stored before the field was switched to `currencyMode: 'record'`. The code is never derived. No flag; idempotent. See [below](#os-migrate-record-currency-codes) |
1542
+
| `os migrate unit-codes` | Rewrite the free text a unit code field stored before it was declared one (`kg`, `公斤`) into unit codes, from a mapping file you give. Nothing is derived. Dry run by default, listing every stored value with its row count; `--apply` is refused while a value has no mapping entry. No flag; idempotent. See [below](#os-migrate-unit-codes) |
1542
1543
| `os migrate recompute-home-amounts` | Recompute the home-currency amounts a record-mode currency field stores, at the exchange rates in force now, after a rate is corrected or added. Reports the rows that change and lists, without writing, the rows it cannot convert. No flag; idempotent. See [below](#os-migrate-recompute-home-amounts) |
1543
1544
| `os migrate comment-reactions` | Carry the emoji reactions a 17.x deployment stored in the retired `sys_comment.reactions` column into `sys_comment_reaction` records, list every stored value that does not read, and record the verified run that lets `os migrate apply --allow-destructive` drop the column |
1544
1545
| `os migrate organization-ownership` | The v18 ownership ceremony (ADR-0131 D10): write a plan of what each table's rows will become, then `--apply` that reviewed plan. It upgrades a database 17.x or an 18.0 pre-release (`18.0.0-next.*`) created; a v18 server refuses to start on one until it has run. See [below](#os-migrate-organization-ownership) |
@@ -1955,6 +1956,101 @@ otherwise; the code, field and object refusals are the command's. It is mounted
1955
1956
the other maintenance routes, so `metadata.endpoints.maintenance: false` takes it away.
1956
1957
There is no Setup button for it yet: that is separate UI work.
1957
1958
1959
+
#### `os migrate unit-codes`
1960
+
1961
+
A `text` field holds whatever its writers typed: `kg`, `KG`, `公斤`. Once the field
1962
+
becomes a unit code field, because a quantity names it as its
1963
+
`unitConfig.unitField` or because it declares `unitConfig: { unitMode: 'code' }`
1964
+
itself, every write of it must hold a unit code, and editing a quantity beside a
1965
+
value there that is free text or blank is refused. The rows already stored keep
1966
+
their text. The save that makes the declaration answers 409 `destructive_change`
1967
+
naming this command (finding `unit_code_field_declared` on the code field, or
1968
+
`unit_mode_to_record` on a stored quantity switched to `unitMode: 'record'`;
Copy file name to clipboardExpand all lines: content/docs/references/api/rest-server.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,7 +228,7 @@ const result = BatchEndpointsConfigSchema.parse(data);
228
228
|**types**|`boolean`| optional (default: `true`) | Mount the metadata type list — `GET /meta` and `GET /meta/types` (one handler, two paths) |
229
229
|**items**|`boolean`| optional (default: `true`) | Mount the per-type item list — `GET /meta/:type`, and nothing else |
230
230
|**item**|`boolean`| optional (default: `true`) | Mount the whole per-item face — `GET`, `PUT` and `DELETE /meta/:type/:name`, its `/references` and `/layers` reads, the history family (`GET``/history`, `/audit`, `/diff`, `/published`; `POST``/publish`, `/rollback`), the package-qualified by-name read `GET /meta/:type/:ns/:name` (ADR-0150 D5), which answers through the item read's own handler, `GET /meta/book/:name/tree` and the app metadata bundle `GET /meta/app/:appId/bundle`, which registers through the same per-item registrar because every member it serves is the item read's own answer |
231
-
|**maintenance**|`boolean`| optional (default: `true`) | Mount the whole-store maintenance operations — `GET /meta/diagnostics`, `GET /meta/_drafts`, the `POST /meta/_migrate-stored` write door and the `POST /meta/_migrate-record-currency-codes` record-currency code backfill |
231
+
|**maintenance**|`boolean`| optional (default: `true`) | Mount the whole-store maintenance operations — `GET /meta/diagnostics`, `GET /meta/_drafts`, the `POST /meta/_migrate-stored` write door, the `POST /meta/_migrate-record-currency-codes` record-currency code backfill and the `POST /meta/_migrate-unit-codes` unit code backfill |
232
232
|**schema**|`never`| optional |[REMOVED]`metadata.endpoints.schema` was removed in @objectstack/spec 17 (ADR-0049 enforce-or-remove) — it gated a route that does not exist: the REST server mounts no `GET /meta/:type/:name/schema`, so `false` removed nothing and `true` added nothing. Delete the key; `endpoints.types` / `items` / `item` / `maintenance` are the switches that gate real mounts. |
0 commit comments