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 3e039e0
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-datasource): a pool rebuild syncs the managed objects bound to the datasource (#27750) (#27874)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D8TexLjwJ2KtVSbiAujiwfF)_Fixes#27750
## 维护者速读
- 改了什么:管理员修改一个 Setup 创建的托管数据源(换库、换凭据、改 schemaMode
或重新启用)导致连接池重建时,绑定到它的代码对象会在新库上建表。
- 为什么改:#27701 只修了"创建"和"重启"两条路;"修改后重建"仍不建表,换库后该对象每次读取都失败,只能手工建表。
- 风险与回滚:只对 `schemaMode: managed` 生效,`external` / `validate-only` 依旧零
DDL;重建失败保留旧池时不同步。回滚 = revert 本 PR。
- 先看:`datasource-admin-plugin.ts` 新的共用 helper `managedObjectsBoundTo`,以及
`reconnect` 新增的 `objects` 参数。
- 两分钟验证:`pnpm --filter @objectstack/service-datasource exec vitest run
src/__tests__/runtime-datasource-bound-object-storage.test.ts`(新增 3
例;回退连接服务的改动后换库那例变红)。
- 需要你做的:无(Tier S,按本期落地授权由席位落地)。
## What changes
- `DatasourceConnectionService.reconnect` takes an optional `objects`
list and forwards it to both of its inner `connect` calls (the swap
rebuild and the nothing-to-swap plain connect), so the connect's sync
loop gives those objects their tables on the pool the new record opens.
The kept-old-pool path syncs nothing.
- `DatasourceAdminServicePlugin`: the managed-only gate and bound-name
list that `registerPool` computed inline (#27701) moved into one helper,
`managedObjectsBoundTo`, which both `registerPool` and `reregisterPool`
call. `reregisterPool` passes the objects bound to the NEW record.
- ⛔ `schemaMode: external` / `validate-only` still pass no objects, so
they never get DDL.
## Why
#27701 synced bound managed objects when a runtime datasource's pool
opens. An admin update that rebuilds the pool (`PATCH
/api/v1/datasources/:name` → `updateDatasource` → `reregisterPool` →
`reconnect`) still passed none, so moving `warehouse` to a new database
left `wh_note` without a table there and every read of it failed.
## Verification
- Pinned red on `main` first: in
`runtime-datasource-bound-object-storage.test.ts` (real plugin, real
`ObjectQL`, SQLite), create `warehouse` on `a.db`, update `config` to
`b.db` → `hasTable('wh_note')` was `false` on `b.db`. Green with the
fix; ablating the connection-service change turns it red again,
restoring turns it green.
- New ⛔ cases: `external` and `validate-only` datasources updated to a
new database sync nothing and create no table.
- `@objectstack/service-datasource`: 63 files / 1031 tests pass; `tsc
--noEmit` clean.
- `dispatch-gates --ran`: 60 derived families accounted for: 59 run
green, 1 NOT MEASURED (`check:dual-build-cjs-loads`, exit 3, needs a
whole-tree build; CI runs it). `pnpm lint` exit 0.
`check:commit-card-trailers` green.
Clause-②: no
Metadata-protocol: none
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [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: n/a.
- [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.
Serial note: draft PR #27819 (#27746) edits both files; this PR keeps to
`reconnect`, `registerPool` / `reregisterPool` and the shared helper.
The later lander merges `main`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4d1ZEsJ6Xne4sn5EXtT
Co-authored-by: Claude <noreply@anthropic.com>
fix(service-datasource): an edit that rebuilds a Setup-created managed datasource's pool gives the objects bound to it their tables on the new pool (#27750)
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
#27701 made a runtime managed datasource's pool sync the objects bound to it when the pool opens. An edit that rebuilds the pool still synced nothing: an admin who moved `warehouse` to a new database (a changed `config`) left every code object bound to it without a table there, and every read of it failed until the tables were recreated by hand.
11
+
12
+
-**Now.** The rebuild (`PATCH /api/v1/datasources/:name` → `updateDatasource` → `reregisterPool` → `DatasourceConnectionService.reconnect`) carries the objects bound to the NEW record into the rebuild's connect, so its sync loop gives them their tables, as on create. The same holds when an edit re-activates an inactive datasource. `reconnect` takes them as a new optional `objects` option.
13
+
-**One gate.** The open (`registerPool`) and the rebuild (`reregisterPool`) read the bound objects through one helper.
14
+
- ⛔ **Only a managed datasource.** A datasource whose `schemaMode` is `external` or `validate-only` syncs nothing for its objects on the rebuild either, so it never gets DDL.
15
+
-**Not changed.** When the rebuild fails and the previous pool is kept, nothing is synced: that pool already served those objects.
0 commit comments