Skip to content

Commit 75d7fb1

Browse files
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec): an Oracle `RAW(16)` uuid column backs a `lookup`, `master_detail` or `user` field exactly again; its `text` pairing stays lossy
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: semantic
9+
10+
`isCompatible(rawType, fieldType, 'oracle')` now answers `true` instead of `'lossy'` for a `RAW(16)` column against `lookup`, `master_detail` and `user`. The SQL driver binds a comparison value, a written value and a by-id key for a `RAW(16)` column as `HEXTORAW(?)`, so a reference field over a `SYS_GUID()` key is filtered, written and resolved by the uuid string it reads. Before that bind existed, every pairing over the column was judged `'lossy'`.
11+
12+
What a caller sees:
13+
14+
- **Draft and validation.** A field of those three types over a `RAW(16)` column is no longer reported as a `type_mismatch` warning by object validation.
15+
- **`text` is unchanged.** A `text` field over a `RAW(16)` column still answers `'lossy'`, and a draft still marks such a column for review. Its pattern operators (`$contains`, `$startsWith`, `$like` and the rest) are sent as text patterns, and Oracle compares them with the column's hex text (32 upper-case digits, no hyphens), not with the uuid string a read returns.
16+
- **Other dialects and other `RAW` widths** answer as before.

‎content/docs/data-modeling/external-datasources.mdx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ object whose `remoteName` is `OWNER.TABLE`.
555555
| `DATE` | `datetime` | An Oracle `DATE` carries a time of day. A `date` field over it is judged lossy: the time is dropped. |
556556
| `TIMESTAMP WITH TIME ZONE` | `datetime` | Compared and returned as UTC instants. |
557557
| `CLOB` | `textarea` | |
558-
| `RAW(16)` | `text` | Read as a lower-case UUID string. Every field pairing over it is judged lossy, so a draft marks it for review: it cannot be filtered or written by that string yet (see below). |
558+
| `RAW(16)` | `text` | Read as a lower-case UUID string, and filtered and written by that string (see below). A `lookup`, `master_detail` or `user` field over it is exact. A `text` field is judged lossy, so a draft marks it for review: `$contains` and the other pattern operators do not match it as the string it reads. |
559559

560560
The driver pins every session to UTC. Thin mode decodes `DATE` and `TIMESTAMP`
561561
values with the server process's local clock, and the driver repairs that on read.
@@ -573,11 +573,20 @@ the process's own time zone. Run the server with `TZ=UTC` and there is no such h
573573
`MERGE`. Use create and update.
574574
- **JSON-array membership** (`$contains` on a multi-value field) is refused. There is
575575
no Oracle construct modelled for it.
576-
- **Filtering or writing a `RAW(16)` column by its UUID string is not supported.**
577-
The driver presents the value as a string on read, but it does not convert the
578-
string back to `RAW` for a comparison or a write. This includes a `lookup` keyed
579-
by a `SYS_GUID()` column. Binding through `HEXTORAW` is tracked in
580-
[#31390](https://github.com/objectstack-ai/objectstack/issues/31390).
576+
- **A `RAW(16)` column is filtered and written by its UUID string.** The driver
577+
reads which of an object's columns are `RAW(16)` from the catalog, and binds a
578+
comparison value (`=`, `$ne`, `$in`, the range operators), a written value and a
579+
record's key for those columns as `HEXTORAW(?)`. That covers a `SYS_GUID()` key and
580+
a `lookup` keyed by one. A UUID is accepted with hyphens (the form a read returns)
581+
or as its 32 hex digits, in either case. Any other value is refused before the
582+
statement is sent: in a filter with `INVALID_FILTER`, in a write with
583+
`VALIDATION_ERROR`. So is a create that gives no id on an object keyed by such a
584+
column, because the id the driver would mint is not a UUID. A `VARCHAR2` column
585+
that holds UUIDs is still compared as text.
586+
- **Pattern operators on a `RAW(16)` column** (`$contains`, `$startsWith`, `$like`
587+
and the rest) are sent as text patterns. Oracle compares them with the column's
588+
hex text: 32 upper-case digits, no hyphens. A fragment of the UUID as it reads
589+
back matches only when it has no hyphen and the operator ignores case.
581590
- A `NUMBER` beyond 2^53 is read as a JavaScript number and loses precision.
582591
- **Paged reads are stable when the object's `columnMap` maps a column to `id`.**
583592
That column breaks ties after the caller's own sort. Without a mapped key, a paged

‎docs/adr/0015-external-datasource-federation.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Deciders**: ObjectStack Protocol Architects
55
**Builds on**: [ADR-0005](./0005-metadata-customization-overlay.md) (one Zod source of truth per metadata type)
66
**Consumers**: `@objectstack/spec`, `@objectstack/runtime`, `@objectstack/objectql`, `@objectstack/plugins/driver-sql`, `@objectstack/services/service-ai`, `@objectstack/cli`, `../objectui`
7-
**Amended by**: [ADR-0143](./0143-outbound-connector-auth-is-open-tier.md) (2026-10-27), attribution only — see the note below. D7 (2026-10-29, ruling 6486136301 on #27298) — an API-backed datasource may borrow a declared connector instance's credential through `external.connector`; see the D7 note below. #27688 (2026-10-30), example only — §8's `credentialsRef` is a `sys_secret:` handle, the only form the shipped secret binder resolves; see the note under §8. #27917 (2026-10-30), dialect list only — §4.6 names the `odata` vocabulary the matrix gained with #27745. #28208 (2026-10-31, ruling 6525963988 on #27687) — a datasource defined in code reads its credential at connect from `OS_DATASOURCE_<NAME>_PASSWORD`, behind the host switch `OS_DATASOURCE_ENV_CREDENTIALS`; see the note under §10 and the correction in the D7 note. 2026-11-03 (maintainer ruling in the security channel, D1 = B, D2 = (c2)+(a)) — under a walled tenancy posture every external object states its organization scope, or the boot is refused by name; see the note under §10 and the sentence added to the D7 note. #31328 (2026-11-08) — §4.6 names the `oracle` vocabulary, with how `NUMBER(p,s)` and `RAW(16)` are read, and its federation-only scope; §5.1 gains the federation-only arm of the DDL gate. #31327 (2026-11-08) — a second federation-only driver, SQL Server (`mssql`): §4.6 names the `mssql` vocabulary and its one dialect-only lossy rule, and the two dialects' lossy moves share one table; §5.1's federation-only arm names both drivers.
7+
**Amended by**: [ADR-0143](./0143-outbound-connector-auth-is-open-tier.md) (2026-10-27), attribution only — see the note below. D7 (2026-10-29, ruling 6486136301 on #27298) — an API-backed datasource may borrow a declared connector instance's credential through `external.connector`; see the D7 note below. #27688 (2026-10-30), example only — §8's `credentialsRef` is a `sys_secret:` handle, the only form the shipped secret binder resolves; see the note under §8. #27917 (2026-10-30), dialect list only — §4.6 names the `odata` vocabulary the matrix gained with #27745. #28208 (2026-10-31, ruling 6525963988 on #27687) — a datasource defined in code reads its credential at connect from `OS_DATASOURCE_<NAME>_PASSWORD`, behind the host switch `OS_DATASOURCE_ENV_CREDENTIALS`; see the note under §10 and the correction in the D7 note. 2026-11-03 (maintainer ruling in the security channel, D1 = B, D2 = (c2)+(a)) — under a walled tenancy posture every external object states its organization scope, or the boot is refused by name; see the note under §10 and the sentence added to the D7 note. #31328 (2026-11-08) — §4.6 names the `oracle` vocabulary, with how `NUMBER(p,s)` and `RAW(16)` are read, and its federation-only scope; §5.1 gains the federation-only arm of the DDL gate. #31327 (2026-11-08) — a second federation-only driver, SQL Server (`mssql`): §4.6 names the `mssql` vocabulary and its one dialect-only lossy rule, and the two dialects' lossy moves share one table; §5.1's federation-only arm names both drivers. #31592 (2026-11-09) — §4.6: with the `HEXTORAW` bind of #31390 on `main`, an Oracle `RAW(16)` column backs a `lookup`, `master_detail` or `user` field exactly again; only its `text` pairing stays `'lossy'`.
88

99
> **Amendment note D7 (2026-10-29, ruling 6486136301, letter A) — a second credential channel.**
1010
> §10 says credentials reach a datasource only through `credentialsRef`. That stays true for a
@@ -429,9 +429,11 @@ read before the matrix strips them (SQL Server's `(max)` length does not: an
429429
integral `NUMBER(p)` / `NUMBER(p,0)` (a negative scale counts its `p − s`
430430
digits) is `integer` up to nine digits and `bigint` beyond, `NUMBER(*,0)` —
431431
Oracle's `INTEGER` — included; a bare `NUMBER` is `decimal`. `RAW(16)` is
432-
`uuid`, any other `RAW` `binary`; on `oracle` every pairing over that `uuid` is
433-
judged `'lossy'`, not exact, because the driver reads it as a UUID string but
434-
cannot yet bind that string back to `RAW` for a filter or a write (#31390). `DATE` carries a time of day, so it is
432+
`uuid`, any other `RAW` `binary`. The driver reads it as a UUID string and binds
433+
that string back through `HEXTORAW` for a comparison, a write and a by-id key
434+
(#31390), so a `lookup`, `master_detail` or `user` field over it is exact; a
435+
`text` field over it stays `'lossy'` on `oracle`, because its pattern operators
436+
match the column's hex text, not the string it reads. `DATE` carries a time of day, so it is
435437
`datetime`. A pre-23ai flag column (`NUMBER(1)` / `CHAR(1)`) is judged as the
436438
integer or text it is, never coerced to `boolean`. The `oracle` and `mssql` driver ids
437439
serve federation only: a datasource naming either with `schemaMode: 'managed'`
@@ -443,7 +445,7 @@ sync would have nothing to send.
443445
names, and maps `timestamp` to binary, because on SQL Server it is the
444446
`rowversion` counter and not a date-time. A dialect moves a pairing to
445447
`'lossy'` in one table, `DIALECT_LOSSY_RULES`, and only ever toward `'lossy'`:
446-
`oracle` demotes the exact pairings of `uuid` (above), and `mssql` adds one, a
448+
`oracle` demotes the exact `text` pairing of `uuid` (above), and `mssql` adds one, a
447449
text column backing a `json`, `tags` or `multiselect` field, because SQL Server
448450
keeps JSON in `nvarchar(max)` and the SQL driver stores those fields there as
449451
JSON text (#31327).

‎packages/spec/src/data/type-compat.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ describe('the oracle dialect (ADR-0015 §4.6)', () => {
392392

393393
it('reads RAW(16) as a UUID and every other RAW width as binary', () => {
394394
expect(canonicalizeSqlType('RAW(16)', 'oracle')).toBe('uuid');
395-
// Read as a UUID string, but the driver cannot yet filter or write it by
396-
// that string, so every pairing over it is flagged for review on oracle.
397-
for (const field of ['text', 'lookup', 'master_detail', 'user'] as const) {
398-
expect(isCompatible('RAW(16)', field, 'oracle'), field).toBe('lossy');
395+
// The driver filters, writes and keys a RAW(16) column by the UUID string
396+
// it reads (HEXTORAW), so a reference field over it is exact on oracle...
397+
for (const field of ['lookup', 'master_detail', 'user'] as const) {
398+
expect(isCompatible('RAW(16)', field, 'oracle'), field).toBe(true);
399399
}
400+
// ...and a text field stays flagged for review: its pattern operators
401+
// match the column's hex text, not the string it reads.
402+
expect(isCompatible('RAW(16)', 'text', 'oracle')).toBe('lossy');
400403
expect(suggestFieldTypeForSqlType('RAW(16)', 'oracle')).toBe('text');
404+
// The demotion names its field types; a type the uuid row does not pair
405+
// exactly is not promoted by it.
406+
expect(isCompatible('RAW(16)', 'number', 'oracle')).toBe(false);
401407
// Other dialects' uuid columns keep their exact pairings.
402408
expect(isCompatible('uuid', 'lookup', 'postgres')).toBe(true);
403409
expect(canonicalizeSqlType('RAW(32)', 'oracle')).toBe('binary');

‎packages/spec/src/data/type-compat.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ const DIALECT_ALIASES: Partial<Record<SqlDialect, Record<string, CanonicalSqlTyp
208208
*
209209
* `RAW(16)` is the conventional Oracle column for a UUID / GUID (`SYS_GUID()`
210210
* returns one), so it maps to `uuid`; every other width is `binary`. The
211-
* field pairings over it are `'lossy'` on oracle, not exact: see
212-
* {@link DIALECT_LOSSY_RULES}.
211+
* reference pairings over it are exact; a `text` field over it is `'lossy'`
212+
* on oracle: see {@link DIALECT_LOSSY_RULES}.
213213
*
214214
* `undefined` for any other spelling — the caller then strips parameters and
215215
* reads the alias tables as for every dialect.
@@ -427,13 +427,20 @@ export function suggestFieldTypeForSqlType(rawType: string, dialect?: SqlDialect
427427
* — never exact, never suggested — so a draft carries a `// REVIEW:` marker
428428
* and validation warns instead of passing silently or failing:
429429
*
430-
* - `demoteExact` — the canonical type's EXACT pairings, which this dialect
431-
* can only half-serve, answer `'lossy'` here.
432-
* `oracle` / `uuid`: a `RAW(16)` column reads back as a UUID string, but the
433-
* driver binds a string comparand or write value as text, and Oracle refuses
434-
* text against RAW. A field over it (a `lookup` keyed by a `SYS_GUID()`
435-
* column included) displays correctly and cannot yet be filtered or written
436-
* by its value. Binding through `HEXTORAW` is #31390.
430+
* - `demoteExact` — the EXACT pairings of the canonical type named here,
431+
* which this dialect can only half-serve, answer `'lossy'` here.
432+
* `oracle` / `uuid` → `text`: the SQL driver reads a `RAW(16)` column as a
433+
* lower-case hyphenated UUID string, and binds a comparison comparand, a
434+
* written value and a by-id key for it as `HEXTORAW(?)` over that string's
435+
* hex digits (#31390). A reference field over it — a `lookup` or
436+
* `master_detail` keyed by a `SYS_GUID()` column, a `user` — is filtered,
437+
* written and resolved by the very string it reads, so those pairings stay
438+
* exact. A `text` field is still half-served: its pattern operators
439+
* (`$contains`, `$startsWith`, `$like`, …) are not bound through
440+
* `HEXTORAW`, so they match the column as the text Oracle converts a
441+
* `RAW` to (its 32 hex digits, upper case, no hyphens), not as the string
442+
* it reads; a fragment of that string with a hyphen, or in the case it is
443+
* read in, answers no row instead of a refusal.
437444
* - `addLossy` — field types the base row answers `false` for, which this
438445
* dialect's column can carry with loss.
439446
* `mssql` / `text`: SQL Server (before its 2025 `json` type) keeps JSON in
@@ -446,12 +453,12 @@ export function suggestFieldTypeForSqlType(rawType: string, dialect?: SqlDialect
446453
* column shape the driver relies on (#31327).
447454
*/
448455
interface DialectLossyRule {
449-
readonly demoteExact?: true;
456+
readonly demoteExact?: readonly FieldType[];
450457
readonly addLossy?: readonly FieldType[];
451458
}
452459

453460
const DIALECT_LOSSY_RULES: Partial<Record<SqlDialect, Partial<Record<CanonicalSqlType, DialectLossyRule>>>> = {
454-
oracle: { uuid: { demoteExact: true } },
461+
oracle: { uuid: { demoteExact: ['text'] } },
455462
mssql: { text: { addLossy: ['json', 'tags', 'multiselect'] } },
456463
};
457464

@@ -468,7 +475,7 @@ export function isCompatible(
468475
const canonical = canonicalizeSqlType(rawType, dialect);
469476
const entry = CANONICAL_TO_FIELD[canonical];
470477
const rule = dialect ? DIALECT_LOSSY_RULES[dialect]?.[canonical] : undefined;
471-
if (entry.exact.includes(fieldType)) return rule?.demoteExact ? 'lossy' : true;
478+
if (entry.exact.includes(fieldType)) return rule?.demoteExact?.includes(fieldType) ? 'lossy' : true;
472479
if (entry.lossy.includes(fieldType) || rule?.addLossy?.includes(fieldType)) return 'lossy';
473480
// Unknown remote types are permissive-but-lossy against text/json only,
474481
// already encoded in CANONICAL_TO_FIELD.unknown.

0 commit comments

Comments
 (0)