Repository navigation
Commit 6d9419b
fix(service-datasource): a runtime managed datasource syncs its bound objects' tables on create and after a restart (#27748)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D1H8LKUgLcNior93UM4jPpL)_
domain:server#3 · os-elon-musk · session_016WV4czbMpdApCUbUuNyHt7
Fixes #27701
## What changes
- `registerPool`
(`packages/services/service-datasource/src/datasource-admin-plugin.ts`)
now opens a runtime datasource's pool with `objects`: the names of the
objects bound to it in the engine registry. The connect's existing sync
loop gives them their tables. This covers the admin create, the boot
rehydration, and a peer replica's convergence on a new datasource, which
all go through `registerPool`.
- ⛔ The objects are passed only when the datasource is managed. Its mode
is read with `resolveDatasourceSchemaMode`, the same read the driver
factory uses. An `external` or `validate-only` datasource passes none
and never gets DDL (triage ruling `6506923793`).
- The registry read that `listObjectsBoundTo` already did is lifted into
one local helper, `objectsBoundTo`, which both readers call.
`listObjectsBoundTo`'s answer is byte-for-byte the same.
- Neither `datasource-connection-service.ts` (open PR #27715) nor
`objectql/src/engine.ts` is touched.
## Why
A code object bound to a Setup-created managed datasource never got its
table. Boot's schema sync skipped it, because the driver did not exist
yet. `registerPool` then called `connect(record, { context })` with no
`objects`, so the sync loop had nothing to sync. The datasource answered
`ok`, and every read of the object was a 500 (Postgres `42P01`), the
same after a restart.
## Verification
New pin:
`src/__tests__/runtime-datasource-bound-object-storage.test.ts`. It uses
the real `DatasourceAdminServicePlugin` through `init()` and `start()`,
a real `ObjectQL` engine on the `objectql` and `data` slots, and the
real default driver factory over SQLite files.
| Case | `origin/main` plugin | this PR |
|---|---|---|
| on create, the bound object's table exists and the object reads | red
| green |
| after a restart, the rehydrated pool creates a missing table and the
object reads | red | green |
| control: an object bound to another datasource is not synced | red |
green |
| ⛔ `schemaMode: external`: the pool opens, nothing is synced | green |
green |
| ⛔ `schemaMode: validate-only`: the pool opens, nothing is synced |
green | green |
Ablations, each restored afterwards:
- Dropping the `objects` argument turns the 3 positive cases red.
- Forcing the managed gate open turns both negative cases red
(`syncObjectSchema` called 2 times).
Local readings at `6f773675`:
- `@objectstack/service-datasource` `test`: 62 files, 1016/1016 passed.
`typecheck`: exit 0.
- `dispatch-gates --commands`: 59 families derived, 58 exit 0. `pnpm
check:dual-build-cjs-loads` exited 3, so it is NOT MEASURED (it needs a
whole-tree build; CI runs it).
- `dispatch-gates --ran`: 59 accounted for.
- `pnpm lint`: exit 0.
Clause-②: no
Metadata-protocol: none
## Acceptance notes
- **Out of scope, measured (class a).** An edit that rebuilds the pool
still syncs nothing. That covers a changed `config`, credential,
`schemaMode` or `active` (`updateDatasource` → `reregisterPool` →
`DatasourceConnectionService.reconnect`). `reconnect` takes no
`objects`, and its inner `connect(record, { context })` is in
`datasource-connection-service.ts`.
- Measured with the same rig: create `warehouse` on `a.db`, then update
its `config` to `b.db`. The result is `hasTable('wh_note') === false`,
and the read is refused by the database.
- `reach:` the admin update door (`PATCH /api/v1/datasources/:name` →
`updateDatasource`). The fix belongs in the connection service, serial
behind #27715.
- A federated object (`external` set) on a managed datasource would go
through `syncObjectSchema`'s DDL-free `registerExternalObject` branch.
The admin door already refuses that binding at write time (#25277).
## 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.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4czbMpdApCUbUuNyHt7
Co-authored-by: Claude <noreply@anthropic.com>1 parent 79d78b4 commit 6d9419b
3 files changed
Lines changed: 256 additions & 18 deletions
File tree
- .changeset
- packages/services/service-datasource/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 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 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
405 | 426 | | |
406 | 427 | | |
407 | 428 | | |
| |||
503 | 524 | | |
504 | 525 | | |
505 | 526 | | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
524 | 530 | | |
525 | 531 | | |
526 | 532 | | |
| |||
529 | 535 | | |
530 | 536 | | |
531 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
532 | 548 | | |
533 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
534 | 556 | | |
| 557 | + | |
535 | 558 | | |
536 | 559 | | |
537 | 560 | | |
| |||
0 commit comments