Repository navigation
Commit 0b89b33
feat(service-automation, metadata-protocol, driver-mongodb, cli): a connector connection is unique per organization and instance (package, name) (#33199)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao3aDjoEUznHeGMZJaoMEKa5)_
Part of #31699
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:按 Tesla 的裁定(连接唯一键「按 包+名字 唯一」),`sys_connector_connection` 的唯一键从
`(organization_id, connector_name)` 加宽为 `(organization_id,
connector_package, connector_name)`。没有包的连接(环境自建或代码注册的连接器实例)靠一条运行时守卫索引
`uniq_sys_connector_connection_packageless`
继续保持每个组织一条。守卫立住之后,旧键在下一次安全同步时被替换(先建后删,`safe`),中间任何时刻都有唯一规则。
- 为什么改:ADR-0150 D4 / D8 R11,#31699 PR 3 的存储一半。下一步(3a-ii)让连接存储、连接门和 OAuth
回调带上包。
- 不变:用户可见的连接行为不变。存储仍按组织+名字读写;一持有者兜底仍然保证每个连接器名只有一个包。
- 风险与回滚:MySQL 8 升级库保留旧键(与 #32164 的授权守卫同一限制,driver-sql
识别修复另开卡);driver-memory 不建守卫。回滚即 revert;守卫索引是额外索引,回滚后旧键由声明重建。
-
先看:`packages/metadata-protocol/src/migrations/connector-connection-packageless-index.ts`(从
#32164
的授权守卫复制,只换常量和措辞)、`packages/services/service-automation/src/connector-connections.ts`(首次连接与回填竞态的回收)、`stored-reference-package-backfill.ts`(`duplicated`)。
## What changes
- **Key.** `sys_connector_connection` declares `{ fields:
['organization_id', 'connector_package', 'connector_name'], unique:
'global' }`. Spelled `'global'` with `organization_id` listed, as #32164
spelled the grant's, because `driver-sql`'s widening arm
(`widenedUniqueReplacements`) does not fire for `'organization'`
(measured: that spelling plans a destructive orphan drop). The arm keeps
the old key until a partial guard on exactly `(organization_id,
connector_name)` stands, then plans one `replace_unique_index`, `safe`,
create-before-drop.
- **Guard.** `uniq_sys_connector_connection_packageless`, built at
`objectql:schema-synced` on every kernel that runs the table's DDL
(`metadata-protocol` `plugin.ts`): partial index on SQLite and
PostgreSQL, functional digest on MySQL 8.0.13+, INVISIBLE generated
column on MariaDB 10.3+, `RUNTIME_OWNED_UNIQUES` on MongoDB (keyed
`(connector_name)`, the key Mongo materialized for the old declaration).
Listed in `runtime-index-preflight.ts` (so `os migrate duplicates`) and
in the CLI's `schema-sync-indexes.ts` (so `os migrate plan` / `apply`).
The module is a copy of `user-permission-set-packageless-index.ts` with
the table's constants and wording.
- **Store.** A first connect that counts a second row of its instance
after its insert (the boot backfill stamped another connect's row
between this one's read and insert, which the old key refused) deletes
its own row and is refused. Everything else in the store is unchanged;
carrying the package is the next PR.
- **Backfill (R11) and bind.** A bind whose update is a unique
violation, confirmed by a read of the row of that key already naming the
holder, is left and reported (`duplicated`), and the walk goes on; the
dry run agrees. `os migrate stored-references bind` refuses it as
`duplicate`.
- **Docs.** `content/docs/deployment/cli.mdx` (runtime-owned indexes,
old-key retirement, MySQL limit, the bind refusal);
`content/docs/automation/connectors.mdx` (one connection per
organization and instance).
## Why
ADR-0150 D4: a connector instance is identified by `(package, name)`,
and D8 row R11 gives the connection its package column. The maintainer
ruled on #31699 that a connection is unique by package and name, so one
organization can connect both packages' instances of one name once the
backstop narrows (the last PR of #31699).
## Verification
- Booted kernel (`service-automation`
`connector-connection-guard-at-schema-sync.test.ts`, real
`ObjectQLPlugin`, SQLite, the shipped object): a second package-less
connection written from a `start()` before `kernel:ready` is refused,
two packages' connections of one name are admitted, a second of one
package's is refused; with `bootPhaseHooks: false` too; a dropped guard
is rebuilt by the next pass. Ablation (guard call removed from the
hook): 3 of 5 red.
- `driver-sql` `sql-driver-widened-connection-key.test.ts`: SQLite (no
guard → old key kept; guard → one safe replace; re-plan empty) and live
PostgreSQL 16 locally; the MySQL cell pins the declared limit (old key
kept) and runs on `main`.
- Guard module: 33 unit tests; live PostgreSQL test green locally; live
MySQL suite runs on `main`. `driver-mongodb` 4 tests (live mongod not
reachable here); `driver-memory` 3 (declared limit).
- Store race: pin + control in `connector-connections.test.ts` (ablation
red). Backfill: 3 new pins in `stored-reference-package-column.test.ts`
(dry run agrees, unconfirmed violation and an R8 violation end the pass;
each red under ablation).
- Full suites: `@objectstack/service-automation` 3843 passed (before the
review round; affected files re-run, 409 passed),
`@objectstack/metadata-protocol` 339 files passed. CLI:
`schema-sync-indexes`, `duplicates.contract`, `stored-references`,
`apply.schema-sync-indexes`, `schema-migrate.grant-guard` green. Build
with declarations, `tsc --noEmit` and `check:test-typecheck` green for
every touched package.
## Red-line read
Run in this thread by a separate review pass (maintainer's instruction:
「你自己有fable,自己审就可以了吧?」). Design round: PASS-WITH-CHANGES (M1–M7, S1–S9,
taken). Code round 1: PASS-WITH-CHANGES, no must-fix, 7 should-fix (a
racing first connect could leave two rows; dry run vs real run; backfill
catch confirmation; docs and changeset wording), all taken. Round 2
(delta): PASS, one should-fix (foreign messages on the new count and
delete) and two changeset notes, taken. Carried to the next PR: the
store reads and counts by package.
## 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.
- [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: its generated artifacts are
regenerated and committed.
- [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 with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibzKCovWpJoMZD6U3NT
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 633d8c4 commit 0b89b33
32 files changed
Lines changed: 2868 additions & 80 deletions
File tree
- .changeset
- content/docs
- automation
- deployment
- permissions
- docs/audits
- packages
- cli/src
- commands/migrate
- utils
- drivers
- driver-memory/src
- driver-mongodb/src
- driver-sql/src
- metadata-protocol/src
- migrations
- services/service-automation/src
- types/src
- scripts
| 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 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
757 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
758 | 760 | | |
759 | 761 | | |
760 | 762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1197 | 1199 | | |
1198 | 1200 | | |
1199 | 1201 | | |
1200 | 1202 | | |
| 1203 | + | |
1201 | 1204 | | |
1202 | 1205 | | |
1203 | | - | |
| 1206 | + | |
1204 | 1207 | | |
1205 | 1208 | | |
1206 | | - | |
1207 | | - | |
| 1209 | + | |
| 1210 | + | |
1208 | 1211 | | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
1209 | 1223 | | |
1210 | 1224 | | |
1211 | 1225 | | |
| |||
1466 | 1480 | | |
1467 | 1481 | | |
1468 | 1482 | | |
1469 | | - | |
| 1483 | + | |
1470 | 1484 | | |
1471 | 1485 | | |
1472 | 1486 | | |
| |||
0 commit comments