Repository navigation
Commit 75d7fb1
feat(spec): an Oracle RAW(16) uuid column backs a lookup, master_detail or user field exactly again (#31786)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbNUZUVQusSTWUaMTSpQuWP8)_
Fixes #31592
Clause-②: yes (widening)
Metadata-protocol: semantic
Skills-docs: none — `git grep -i
'raw(16)|HEXTORAW|isCompatible|type-compat|lossy' -- skills
.claude/skills` has 0 hits; no skill states this matrix.
## 维护者速读
- 改了什么:Oracle 联邦表里 `RAW(16)` 的 uuid 列,配 `lookup` / `master_detail` /
`user` 字段时,类型兼容矩阵从「有损」改回「精确」;配 `text` 字段仍判有损。只改 `packages/spec`
的判定函数,外加文档、ADR-0015 §4.6 和 changeset。
- 为什么改:#31390(PR #31642)已让 driver-sql 用 `HEXTORAW(?)` 绑定这类列的比较值、写入值和按 id
定位的键,所以 `SYS_GUID()` 主键上的 lookup 现在能按读出来的 uuid
筛选、写入、改删。矩阵还标着有损,校验就会对每个这样的 lookup 报 `type_mismatch` 警告。
- 风险与回滚:这是放宽(Clause-② widening):校验对这三种字段不再报警告。`text` 不放宽,因为 `$contains`
这类模式运算符没走 `HEXTORAW`,Oracle 会拿列的大写无横线十六进制去匹配,用读出来的 uuid 片段搜不到行,也不报错。回滚即
revert 本 PR。
- 先看:`packages/spec/src/data/type-compat.ts`(`DIALECT_LOSSY_RULES` 的
oracle 行和 `isCompatible`
第一行判断)、`docs/adr/0015-external-datasource-federation.md`
§4.6、`content/docs/data-modeling/external-datasources.mdx` 的 Oracle 一节。
- 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run
src/data/type-compat.test.ts`,预期 42 个测试全绿;其中 RAW(16) 一条断言 lookup /
master_detail / user 为 `true`、text 为 `'lossy'`。
- 需要你做的:审批本 PR(改动含受管面 `docs/adr/**`,Tier H),之后由席位落地。
## What changes
- **`isCompatible`, oracle `RAW(16)`.** `DialectLossyRule.demoteExact`
was a flag that demoted every exact pairing of the canonical type. It is
now the list of exact pairings it demotes. The oracle `uuid` row names
`text` only. So `isCompatible('RAW(16)', 'lookup' | 'master_detail' |
'user', 'oracle')` answers `true` (was `'lossy'`), and `'text'` still
answers `'lossy'`. The rule type is module-private, so no export
changes.
- **The member stays live.** `demoteExact` is still used by oracle for
`text`, so it is not dead. `mssql` / `text` `addLossy` is unchanged.
- **JSDoc.** The `DIALECT_LOSSY_RULES` docblock no longer says "Binding
through `HEXTORAW` is #31390". It now says what the driver binds and why
`text` is still demoted. The `RAW(n)` paragraph above
`oracleParameterisedType` matches.
- **Docs.** In `external-datasources.mdx`, the `RAW(16)` table row says
the column is filtered and written by its uuid string. It says a
reference field over it is exact and a `text` field is lossy. The old
"not supported" bullet now describes the bind, the accepted uuid forms,
and the refusals the #31390 changeset names (`INVALID_FILTER`,
`VALIDATION_ERROR`, a create with no id on a `RAW(16)` key). A new
bullet says what the pattern operators match.
- **ADR-0015 §4.6.** The `RAW(16)` sentence and the
`DIALECT_LOSSY_RULES` sentence (both in §4.6) are corrected. The
`Amended by` line gains a dated `#31592 (2026-11-09)` entry.
- **Changeset.** `.changeset/31592-oracle-raw16-reference-exact.md`,
`@objectstack/spec` `minor`, carrying both declaration lines.
## Why
Card task (Ruling-ref: ADR-0015 §4.6): "drop the oracle / `uuid`
`demoteExact` rule (or narrow it) so `RAW(16)` → `lookup` /
`master_detail` answers compatible again". Also: "the pairing must not
be declared before the runtime honours it". Triage 6724356074: "Moving a
type-compat pair from `lossy` to compatible widens an acceptance set,
which is a metadata-protocol change under #31424 rule 2."
**Which paths #31390 binds, read on `main` (`836d408f`).** I checked
these in `packages/drivers/driver-sql/src/` and the #31390 tests in
`sql-driver-oracle-dialect.test.ts`.
- Comparison comparands (`=`, `$eq`, `$ne`, `$in`, `$nin`, the range
operators) bind through `HEXTORAW`. See `coerceFilterValue` and
`assertOracleUuidComparand`, in both the operator-object and
bare-equality branches.
- Written values (create, update, bulk) bind through it.
- The by-id key of update, delete, bulkDelete and the post-insert
read-back binds through it.
- Lookup expansion reads the target by `{ id: { $in: [...] } }`
(`packages/objectql/src/engine-summaries-and-expansion.ts` L593), which
is the comparand path.
So `lookup`, `master_detail` and `user` are honoured, and the narrowing
lifts exactly those three.
**What is still not honoured: pattern operators.** The pin `control: a
pattern operator on the RAW(16) column compiles its text pattern as
before, unjudged` shows it: `$contains: 'abc'` compiles to `"ACCT_REF"
LIKE ? ESCAPE ?` with `'%abc%'`, with no `HEXTORAW` and no conversion.
Oracle converts a `RAW` to character data as its hex digits (upper case,
no hyphens). A fragment of the string a read returns matches no row if
it holds a hyphen, and under a case-sensitive operator (`$contains`,
`$startsWith`) a lower-case fragment matches none at all. No error is
raised. For a `text` field those operators are its own (list search is
an `$or` of `$icontains`, `packages/objectql/src/search-filter.ts`), so
`text` stays `'lossy'` and a draft keeps its `// REVIEW:` marker. A
reference field is filtered by id equality or membership, which is
bound.
**Consumers of `isCompatible` on `main`**
(`packages/services/service-datasource/src/external-datasource-service.ts`):
- L957, draft `// REVIEW:`: no change. It judges the suggested type,
which for `RAW(16)` is `text`, and that stays `'lossy'`.
- L1113, the `!== true` lookup gate: no change for oracle. It runs only
for OData `navigationProperties` (`navigationCandidates`), and a SQL
table has none.
- L1339, `validateObject`: a `lookup` / `master_detail` / `user` field
over an oracle `RAW(16)` column no longer gets the `type_mismatch`
warning. `text` keeps it.
- Test pins in service-datasource that hold the `'lossy'` answer: none.
`git grep -n -i "RAW(16)\|demoteExact"` in
`packages/services/service-datasource` finds 0. The suite is green
unchanged (see Tests).
- The only other mention is a docblock in
`driver-sql/src/builtin-column-collision.ts`, which is not about oracle.
## Tests
- `packages/spec/src/data/type-compat.test.ts`, the `RAW(16)` case:
`lookup`, `master_detail`, `user` now pin `true`, and `text` pins
`'lossy'`. It also pins that the demotion promotes nothing (`number`
stays `false`). The suggested type is still `text`. Postgres `uuid` /
`lookup` is still `true`, and other `RAW` widths are still `binary`.
- **Ablation 1** (`scripts/ablation-replace.mjs`, mutation proven on
disk, restored to HEAD): `isCompatible` back to the flag reading
(`rule?.demoteExact ? 'lossy' : true`). Result: red, `lookup: expected
'lossy' to be true`, 1 failed / 41 passed.
- **Ablation 2**: the oracle row as `demoteExact: []`. Result: red,
`expected true to be 'lossy'` (the `text` leg), 1 failed / 41 passed.
- Both ran against `src` (the spec suite imports `./type-compat`
directly), so no `dist` preflight applies.
## Acceptance notes
- **Live Oracle: NOT MEASURED.** No `OS_TEST_ORACLE_URL` here. The
`HEXTORAW` bind is #31390's, and its live conformance cell is also
unmeasured in CI. The claim that pattern operators match the hex text
rests on Oracle's documented implicit `RAW` to character conversion and
on the compiled-SQL pin above, not on a live run.
- **Scope.** All edits are inside the claim's file surface. In ADR-0015
the edits are the §4.6 `RAW(16)` sentence (L431-434), the
`DIALECT_LOSSY_RULES` sentence in the same §4.6 that said oracle
"demotes the exact pairings of `uuid`" (which this change makes false),
and the `Amended by` line. No `driver-sql` change.
- **A base-row observation, not changed here.** The `uuid` row keeps
`user` exact on every dialect. A platform user id is a 32-character
better-auth string or a 16-character nanoid, never a uuid. So a uuid
column (postgres `uuid`, mssql `uniqueidentifier`, and now oracle
`RAW(16)` too) refuses a real platform user id on write. That is the
base row's judgement, the same on every dialect, and this card does not
reopen it. Noted, not filed.
- **`create` without an id** on an object keyed by a `RAW(16)` column is
`VALIDATION_ERROR` (the minted nanoid is not a uuid), per #31390. The
docs bullet now says so.
## Verification
Head `e090be93` (`0a902b02` merged with `origin/main` at `f6474306`).
`main` moved nothing under `packages/spec` or
`packages/services/service-datasource` in that merge.
<details><summary>Suites</summary>
- `pnpm --filter @objectstack/spec build`: VERDICT command-exit 0,
rebuilt after the merge.
- `pnpm --filter @objectstack/spec check:generated`: exit 0, "All 14
generated artifacts are up to date".
- `pnpm --filter @objectstack/spec test`: 824 files passed, 26081 tests
passed, 1 todo, VERDICT command-exit 0.
- `pnpm --filter @objectstack/spec typecheck`: VERDICT command-exit 0.
- `pnpm --filter @objectstack/service-datasource test` (consumer, after
its `^...` closure build): 74 files, 1299 tests passed, VERDICT
command-exit 0.
- Built `dist` reading: `isCompatible('RAW(16)', X, 'oracle')` gives
text `lossy`, lookup `true`, master_detail `true`, user `true`, number
`false`. Postgres `uuid` / lookup is `true`, mssql `nvarchar(max)` /
json is `lossy`.
- `spec` `test:repo` was not run locally. It is CI's (Test Core).
</details>
<details><summary>Derived gates</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derives 108 families. 107 exited 0.
- `pnpm check:dual-build-cjs-loads` exited 3 (PREREQUISITE NOT MET: it
needs a full workspace build). That is NOT MEASURED locally, and CI runs
it.
- Three gates first exited 3 on unbuilt prerequisites
(`check:doc-formula-expressions`, `check:doc-security-posture`,
`check:skill-examples`). Each exited 0 after a locked `turbo run build`
of formula, lint and client-react.
- After the merge with `main`, the five gates whose scripts the merge
moved were re-run, each exit 0: `check:ci-filter-parity`,
`check:cross-package-test-inputs`, `check:pm-governed-merges`,
`check:engine-double-contract`, `check:adr-anchors`.
- `--ran` reconciliation: 108 derived, 107 run, 1 NOT-MEASURED, 0 UNRUN.
- `dispatch-gates --tier`: `docs/adr/**` is Tier H. Changed lines: 94,
under 3000.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [ ] 3. No formatter ran; `pnpm lint` passes. (No formatter ran. `pnpm
lint` is CI's.)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (`check:generated` reports none stale.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jULf9M1RFFq4dq9ioH)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 38ce26f commit 75d7fb1
5 files changed
Lines changed: 67 additions & 27 deletions
File tree
- .changeset
- content/docs/data-modeling
- docs/adr
- packages/spec/src/data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
558 | | - | |
| 558 | + | |
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
581 | 590 | | |
582 | 591 | | |
583 | 592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
433 | | - | |
434 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
| |||
443 | 445 | | |
444 | 446 | | |
445 | 447 | | |
446 | | - | |
| 448 | + | |
447 | 449 | | |
448 | 450 | | |
449 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
399 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
400 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
401 | 407 | | |
402 | 408 | | |
403 | 409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
212 | | - | |
| 211 | + | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
437 | 444 | | |
438 | 445 | | |
439 | 446 | | |
| |||
446 | 453 | | |
447 | 454 | | |
448 | 455 | | |
449 | | - | |
| 456 | + | |
450 | 457 | | |
451 | 458 | | |
452 | 459 | | |
453 | 460 | | |
454 | | - | |
| 461 | + | |
455 | 462 | | |
456 | 463 | | |
457 | 464 | | |
| |||
468 | 475 | | |
469 | 476 | | |
470 | 477 | | |
471 | | - | |
| 478 | + | |
472 | 479 | | |
473 | 480 | | |
474 | 481 | | |
| |||
0 commit comments