Skip to content

Commit ce965cf

Browse files
feat(service-datasource): the Studio connection form offers Oracle and SQL Server, federation only (#31632)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi97vPuFfB4ofnDGXxVYd3NjZ)_ Fixes #31389 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - **改了什么**:Studio「新建数据源」的驱动下拉新增 Oracle Database 和 SQL Server 两项;选中它们时,「结构模式」只提供「外部」和「仅校验」,不再提供「托管」,并在下方用一句话说明原因。 - **为什么改**:这两个驱动此前已经落地(只做联邦),但只能在代码里声明,管理员无法在界面上连接已有的老库(ERP、财务库)。 - **风险与回滚**:驱动目录接口的每个条目可能多出一个新字段 `federationOnly: true`(只出现在这两个驱动上),属于加宽;其它驱动条目字节不变。回滚即整体 revert。 - **先看**:① `packages/services/service-datasource/src/driver-catalog.ts`(新条目与 `federationOnly` 投影)② `ui/packages/app-shell/src/views/metadata-admin/datasource/DatasourceResourcePage.tsx` 的 `schemaModesFor` 与切换驱动时的模式回落 ③ `driver-catalog-translations.ts` 十种语言的新词。 - **两分钟验证**:`pnpm --filter @objectstack/service-datasource exec vitest run src/__tests__/driver-catalog.test.ts`,预期 37 条全过。 - **需要你做的**:无,席位落地。 ## What changes - **`@objectstack/service-datasource`**: `DRIVER_CATALOG` (served by `GET /api/v1/datasources/drivers`) gains `oracle` (label `Oracle Database`) and `mssql` (label `SQL Server`). Their `configSchema` is the spec projection (`getDriverConfigJsonSchemaById`), like every other entry; nothing in the catalog loads `oracledb` or `tedious`. Each carries a new key, `federationOnly: true`, projected from the spec's `FEDERATION_ONLY_DRIVER_IDS` and not restated; it is absent (never `false`) on every other entry, the way the spec column it projects is. The old module note saying `mssql` is left out is replaced by one saying why the federation-only drivers are offered. - **Translations**: `driver-catalog-translations.ts` carries both drivers' description and every connection field's title and description in all ten non-English languages on the platform locale table (the same set every other entry carries). Product names (`Oracle Database`, `SQL Server`) are not translated, like `PostgreSQL`. - **`@object-ui/app-shell`**: the New datasource dialog reads the catalog's `federationOnly`. For a marked driver the Schema mode select offers External and Validate only (the two federation modes the spec accepts), never Managed, and one sentence under it says why. A Managed choice made on another driver moves to External when a marked driver is chosen. No driver id is written in `ui/`. - **Missing `tedious` remedy** (seat 1 patch round): `tedious`, the package knex's `client: 'mssql'` requires, joins `OPTIONAL_DRIVER_CLIENT_PACKAGES` in `connect-failure-remedy.ts`, so a SQL Server datasource without it is refused with the install of `tedious` as its remedy, like `pg`, `mysql2`, `better-sqlite3` and `oracledb`; before, it was told to run `pnpm install && pnpm build`. This PR is what puts SQL Server in the form, so it is what makes that answer reachable. - **`@object-ui/i18n`**: one new studio key, `engine.datasource.schemaModeFederationOnly` (en, zh). - Changeset: `.changeset/31389-federation-only-driver-catalog.md` (patch on all three packages). ## Tests - `driver-catalog.test.ts`: the id list now ends `oracle`, `mssql` (forced edit: the published id list grew); `PRODUCT_NAME_LABELS` gains both (forced edit: their labels are product names); the icon equality across languages now also compares `federationOnly` (forced edit). New: the mark is exactly `FEDERATION_ONLY_DRIVER_IDS` and absent on every other entry; the spec refuses either driver as `managed` and accepts it as `external` / `validate-only`; Simplified Chinese words for both and the mark kept through localisation. The coverage battery walks every language over both new entries. - `missing-driver-client-boot-refusal.test.ts`: a `tedious` arm beside the `oracledb` one (real factory, real `SqlDriver`, knex's genuine `Cannot find module 'tedious'`): the `mssql` default is refused, ending on `missingDriverClientRemedy('tedious')`, never the build sentence. - `DatasourceResourcePage.newDatasourceModes-30327.test.tsx` (the dialog's existing schema-mode harness, new top-level `describe`; its served driver list gains the two catalog entries): (h) Oracle and SQL Server offer exactly External and Validate only, the reason sentence shows, Create sends `schemaMode: 'external'` with `external: {}`; (i) Managed chosen on PostgreSQL moves to External on choosing SQL Server; (j) CONTROL: PostgreSQL offers all three modes and no reason sentence; zh reads in Chinese. <details><summary>Ablations (each red, then restored; git diff HEAD empty after each)</summary> All four through `scripts/ablation-replace.mjs` (anchor hit 1 → 0, blob moved, restored to the HEAD blob). The suites import source directly, so no dist leg. 1. Catalog: `federationOnly` set on every entry (`false` on unmarked ones) → `marks exactly the spec's federation-only drivers, and no other entry` red (`memory: expected true to be false`), plus the zh mark test; 2 failed / 35 passed. 2. Form: `schemaModesFor` returns all three modes for a marked driver → (h) Oracle, (h) SQL Server (`expected [ …(3) ] to deeply equal [ …(2) ]`) and (i) red; 3 failed / 9 passed. 3. Form: reason sentence rendered for any driver → (j) CONTROL red (the reason paragraph was found where null was expected); 1 failed / 11 passed. 4. Remedy: `tedious` taken back out of `OPTIONAL_DRIVER_CLIENT_PACKAGES` → `tedious absent: the mssql default is refused, ending on the install of that client` red (`expected false to be true`); 1 failed / 6 passed. </details> ## Acceptance notes - **Clause-② measured `yes (widening)`, not the claim's `no`**: the form needs the federation-only fact and the card says it must read it from the catalog, so the catalog answer gains a key. Measured on base `6b83ec2d` vs head through `driverCatalogFor(undefined | 'zh-CN')`: base serves 5 entries, each with keys `configSchema,description,icon,id,label`; head serves 7, the five unchanged and `oracle` / `mssql` with `configSchema,description,federationOnly,icon,id,label`. - **New public key `federationOnly`**: spelled after the spec column it projects (`DriverVocabularyEntry.federationOnly`, `true` or absent). The seat rules the name. - **Validate only stays offered**: the card says the form offers only `external`. The spec accepts both federation modes for these drivers (`federationOnly` doc: `schemaMode: 'external'` / `'validate-only'`), and the form offers Validate only for every driver, so only Managed is withheld. Hiding Validate only too would also leave an existing `validate-only` SQL Server row's edit dialog with a selected value no option names. - **Stale QA checklist text**: `docs/qa/platform-checklist/areas/integration-system.json` lines 1341 and 1353 describe the catalog as `memory/sqlite/postgres/mysql/mongodb`; it now also lists `oracle` and `mssql`. Outside the claim's file surface, so not edited here. - **Seat rulings**: `Clause-②: yes (widening)` as measured and the key name `federationOnly` stand; Validate only stays offered (the spec, not the card's wording, decides); the full app-shell suite is left to CI `Test UI`. ## Verification At head `0f59ea948`: - `pnpm --filter @objectstack/service-datasource test`: 74 files, 1295 / 1295 passed; `typecheck` exit 0. - `@object-ui/i18n`: test 99 files, 1804 passed / 13 skipped; `type-check` exit 0. `@object-ui/app-shell`: `type-check` exit 0; `src/views/metadata-admin/datasource/` 9 files, 59 / 59 passed. The full app-shell suite (2218 files) is left to CI `Test UI` (declared narrowing). - Lint: root eslint on `packages/services/service-datasource` exit 0; `@object-ui/i18n` and `@object-ui/app-shell` `lint` exit 0 (warnings only, none on changed lines). - Gates: `node scripts/pm/dispatch-gates.mjs --commands` at `0f59ea948` derived 68 families (the new one: `check:optional-error-sink`); all 68 ran with exit 0 on the first pass (`--ran`: 68 run, 0 NOT-MEASURED, 0 UNRUN). At `f6295c173` the 67 then derived were likewise all green. - Dogfood battery (asked for by the dispatch), at `f6295c173`, before the remedy commit; not re-run on `0f59ea948`: `pnpm --filter @objectstack/dogfood test` under the lock, VERDICT command-exit 0, 443 files (440 passed, 3 skipped), 3674 tests (3633 passed, 41 skipped). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (no `packages/spec` edit) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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: not touched. - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmNeNnbFawUQhsi5pXU)_ <!-- signed: domain:server#1 · os-steve · session_01ADHkmPF1skfu2kx89BEXZi --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent b2ce250 commit ce965cf

10 files changed

Lines changed: 384 additions & 15 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/service-datasource': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat(service-datasource): the Studio connection form offers Oracle and SQL Server, federation only
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
`GET /api/v1/datasources/drivers` now lists `oracle` (Oracle Database) and `mssql` (SQL Server). Each entry's connection fields are projected from the driver's config contract in `@objectstack/spec`, like every other entry, and its words are served in every language on the platform locale table.
13+
14+
Both drivers serve federation only (ADR-0015 §4.6), so their entries carry a new key, `federationOnly: true`, read from the spec's `FEDERATION_ONLY_DRIVER_IDS`. The key is absent on every other entry; a client that does not read it sees two more entries and nothing else changed.
15+
16+
The New datasource dialog reads that key from the catalog: for Oracle and SQL Server its Schema mode select offers External and Validate only, never Managed (the spec refuses a managed datasource naming either), and one sentence under it says why. A Managed choice made on another driver moves to External when one of them is chosen. As with PostgreSQL and MySQL, the database client (`oracledb`, `tedious`) is an optional install next to the server. A SQL Server datasource whose `tedious` is missing is now refused with the install of `tedious` as its remedy, like the other clients; it used to be told to rebuild the workspace.

‎packages/services/service-datasource/src/__tests__/driver-catalog.test.ts‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import { describe, it, expect } from 'vitest';
2020
import {
21+
DatasourceSchema,
22+
FEDERATION_ONLY_DRIVER_IDS,
2123
getDriverConfigJsonSchemaById,
2224
validateDriverConfig,
2325
type BuiltinDriverId,
@@ -54,7 +56,40 @@ describe('DRIVER_CATALOG', () => {
5456
// the assertion is the one that has to move with the rename — stored rows
5557
// carrying `mongo` are converged by the ADR-0087 conversion
5658
// `datasource-driver-mongo-to-mongodb`.
57-
expect(DRIVER_CATALOG.map((d) => d.id)).toEqual(['memory', 'sqlite', 'postgres', 'mysql', 'mongodb']);
59+
expect(DRIVER_CATALOG.map((d) => d.id)).toEqual([
60+
'memory', 'sqlite', 'postgres', 'mysql', 'mongodb', 'oracle', 'mssql',
61+
]);
62+
});
63+
64+
/**
65+
* The federation-only drivers (ADR-0015 §4.6) are offered, each marked so
66+
* the form leaves the managed schema mode out. The mark is the spec's
67+
* `FEDERATION_ONLY_DRIVER_IDS` projected, so the set is compared to that
68+
* export, not to a list written here.
69+
*/
70+
it('marks exactly the spec\'s federation-only drivers, and no other entry', () => {
71+
expect([...FEDERATION_ONLY_DRIVER_IDS].sort()).toEqual(['mssql', 'oracle']);
72+
const marked = DRIVER_CATALOG.filter((d) => d.federationOnly === true).map((d) => d.id);
73+
expect(marked.sort()).toEqual([...FEDERATION_ONLY_DRIVER_IDS].sort());
74+
for (const entry of DRIVER_CATALOG) {
75+
if (marked.includes(entry.id)) continue;
76+
expect(Object.prototype.hasOwnProperty.call(entry, 'federationOnly'), entry.id).toBe(false);
77+
}
78+
});
79+
80+
it('a federation-only entry is the mode the spec refuses as managed and accepts as external', () => {
81+
const configs: Record<string, Record<string, unknown>> = {
82+
oracle: { connectString: 'db.example.com:1521/ORCLPDB1' },
83+
mssql: { host: 'sql.example.com', database: 'erp' },
84+
};
85+
for (const id of FEDERATION_ONLY_DRIVER_IDS) {
86+
const base = { name: 'legacy', driver: id, config: configs[id] };
87+
expect(DatasourceSchema.safeParse({ ...base, schemaMode: 'managed' }).success, `${id} managed`).toBe(false);
88+
for (const schemaMode of ['external', 'validate-only']) {
89+
const parsed = DatasourceSchema.safeParse({ ...base, schemaMode, external: {} });
90+
expect(parsed.success, `${id} ${schemaMode}: ${JSON.stringify(parsed.error?.issues)}`).toBe(true);
91+
}
92+
}
5893
});
5994

6095
/**
@@ -97,7 +132,7 @@ const entryOf = (catalog: typeof DRIVER_CATALOG, id: string) => {
97132
const filenameTitle = (tag: string | undefined) => propsOf(entryOf(driverCatalogFor(tag), 'sqlite')).filename.title;
98133

99134
/** The labels that are product names, served as written in every language. */
100-
const PRODUCT_NAME_LABELS = new Set(['sqlite', 'postgres', 'mysql', 'mongodb']);
135+
const PRODUCT_NAME_LABELS = new Set(['sqlite', 'postgres', 'mysql', 'mongodb', 'oracle', 'mssql']);
101136

102137
/**
103138
* The catalog's words in the requester's language. The New datasource dialog
@@ -125,6 +160,26 @@ describe('driverCatalogFor', () => {
125160
expect(entryOf(zh, 'memory').label).toBe('内存');
126161
});
127162

163+
it('serves Simplified Chinese words for the federation-only drivers, and keeps their mark', () => {
164+
const zh = driverCatalogFor('zh-CN');
165+
166+
const oracle = entryOf(zh, 'oracle');
167+
expect(oracle.label).toBe('Oracle Database');
168+
expect(oracle.federationOnly).toBe(true);
169+
expect(propsOf(oracle).connectString.title).toBe('连接字符串');
170+
expect(propsOf(oracle).serviceName).toMatchObject({ title: '服务名', description: '数据库服务名' });
171+
expect(propsOf(oracle).host).toMatchObject({ title: '主机', description: '监听器主机地址' });
172+
173+
const mssql = entryOf(zh, 'mssql');
174+
expect(mssql.label).toBe('SQL Server');
175+
expect(mssql.federationOnly).toBe(true);
176+
expect(propsOf(mssql).instanceName.title).toBe('实例名');
177+
expect(propsOf(mssql).ssl.title).toBe('加密(TLS)');
178+
expect(propsOf(mssql).host).toMatchObject({ title: '主机', description: '主机地址' });
179+
180+
expect(Object.prototype.hasOwnProperty.call(entryOf(zh, 'postgres'), 'federationOnly')).toBe(false);
181+
});
182+
128183
it('serves a word of its own in every language on the platform table', () => {
129184
const expected: Record<string, string> = {
130185
'zh-Hans': '文件名',
@@ -164,7 +219,8 @@ describe('driverCatalogFor', () => {
164219
it('keeps everything but the words: ids, icons, types and defaults are the English entry\'s', () => {
165220
for (const tag of PLATFORM_LOCALE_TAGS) {
166221
const served = driverCatalogFor(tag);
167-
expect(served.map((d) => [d.id, d.icon]), tag).toEqual(DRIVER_CATALOG.map((d) => [d.id, d.icon]));
222+
expect(served.map((d) => [d.id, d.icon, d.federationOnly]), tag)
223+
.toEqual(DRIVER_CATALOG.map((d) => [d.id, d.icon, d.federationOnly]));
168224
for (const entry of served) {
169225
const english = propsOf(entryOf(DRIVER_CATALOG, entry.id));
170226
const translated = propsOf(entry);

‎packages/services/service-datasource/src/__tests__/missing-driver-client-boot-refusal.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ describe('a missing database client refuses the boot with ITS install (#24909)',
163163
['better-sqlite3', 'sqlite', () => ({ filename: join(scratch, 'app.db') })],
164164
// #31328 — federation only, so the datasource declares `schemaMode: 'external'`.
165165
['oracledb', 'oracle', () => ({ host: '127.0.0.1', port: 1, serviceName: 'FREEPDB1', username: 'app', schemaMode: 'external' })],
166+
// SQL Server, federation only too; knex's `mssql` client requires `tedious`.
167+
['tedious', 'mssql', () => ({ host: '127.0.0.1', port: 1, database: 'app', username: 'app', schemaMode: 'external' })],
166168
];
167169

168170
it.each(arms)('%s absent: the %s default is refused, ending on the install of that client', async (client, driver, config) => {

‎packages/services/service-datasource/src/connect-failure-remedy.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,16 @@ export const UNBUILT_WORKSPACE_REMEDY =
181181
* The database clients `@objectstack/driver-sql` loads through knex and that a
182182
* project installs itself — the client each SQL arm of the shared factory names
183183
* (`client: 'pg'` / `'mysql2'` / `'better-sqlite3'` / `'oracledb'`; knex
184-
* requires the package of the same name). A module-not-found naming one of these, as a bare
184+
* requires the package of the same name), plus `tedious`, the package knex's
185+
* `client: 'mssql'` requires for SQL Server. A module-not-found naming one of these, as a bare
185186
* specifier, is a missing install and not an unbuilt workspace.
186187
*
187188
* Closed on purpose: a name on this list is promised the install remedy, so it
188189
* holds only the clients whose install is known to be the fix. The pins build
189190
* each one's real failure through the real factory arm, so a renamed client
190191
* shows up there rather than as a silent return to the build advice.
191192
*/
192-
export const OPTIONAL_DRIVER_CLIENT_PACKAGES: readonly string[] = ['pg', 'mysql2', 'better-sqlite3', 'oracledb'];
193+
export const OPTIONAL_DRIVER_CLIENT_PACKAGES: readonly string[] = ['pg', 'mysql2', 'better-sqlite3', 'oracledb', 'tedious'];
193194

194195
/**
195196
* The remedy when the database client the driver loads is not installed.

0 commit comments

Comments
 (0)