Repository navigation
Commit 76684a7
fix(driver-sql): the orphan arm keeps a hash-shadow carrier whose key it could not read, never an orphan drop (#32430)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgHNGYL5R2Qt6GA5ZKKhvoKT)_
Fixes #32399
domain:server#2 · os-bill · session_01Utp6CaP1iy4RSEQbW6177G
Clause-②: no
- The orphan arm of `diffManagedIndexes`, on a #11627 hash-shadow
carrier under an ObjectStack generated name whose generation expression
could not be read: FROM `unmapped_index` / `drop_index`, categorized
`destructive` (performed by `os migrate apply --allow-destructive`) TO
kept, nothing offered. No authored key, wire shape, or non-destructive
answer moves; the one thing withdrawn is an opt-in drop of a constraint
whose key the planner could not read, which `isHashShadowCarrier`'s own
contract already ruled out. A RESOLVED orphan carrier is still offered
as the drop.
Metadata-protocol: none
Skills-docs: none. `git grep -i -E 'hash.?shadow|__hash|shadow
carrier|orphan(ed)? index|drop_index' -- skills content/docs` (releases
excluded) has 1 hit, `content/docs/deployment/cli.mdx` line 1182, the
`drop_index` row of the index-drift table ("An index carrying
ObjectStack's generated naming that metadata no longer declares"). It
says what the op means, not that every such index gets it
(runtime-managed partial and expression indexes were already excluded
without a sentence there), so this change makes it no less true.
## 维护者速读
1. 改了什么:driver-sql 的 schema 差异比对里,"孤儿索引"这条规则遇到 MySQL/MariaDB
上读不出所哈希键的影子列唯一索引时,不再提议删除(destructive),改为保留、什么都不提议;读得出键的孤儿影子索引照旧提议删除。
2. 为什么改:读不出键就不知道删掉的是哪条唯一约束;`os migrate apply --allow-destructive`
会把它删掉,数据从此静默失去这条约束。加宽分支和重定义分支早已这样处理,只差孤儿分支。
3.
风险与回滚:只会把一条"提议删除"变成"保留",不新增任何操作;代价是这种读不出键、声明又确实已删掉的影子索引不再出现在计划里(与另两条分支相同的取舍:少一条发现,绝不丢一条约束)。回滚即还原本
PR。
4. 先看:`packages/drivers/driver-sql/src/schema-drift.ts` 里
`diffManagedIndexes` 第 3 段(孤儿分支)新加的一行守卫与注释。
5. 两分钟验证:`pnpm --filter @objectstack/driver-sql exec vitest run
src/sql-driver-13015-shadow-carried-index-drift.test.ts`,预期 11 个过、2
个实库单元无 MySQL 时具名跳过(设 `OS_TEST_MYSQL_URL` 则 16
个全跑);读不出键的影子索引不出现在结果里,读得出键的那个仍是 `drop_index`。
6. 需要你做的:无,席位落地。
## What changes
`packages/drivers/driver-sql/src/schema-drift.ts`, section 3 of
`diffManagedIndexes` (the orphan arm): one guard, `if
(isHashShadowCarrier(p) && !p.shadowKey) continue;`, placed after the
runtime-managed skip and before the orphan entry is built. It is the
redefinition arm's guard, byte for byte, with the same load-bearing
`!p.shadowKey` half: a carrier whose key was resolved is not exempted
and is still offered as the orphan drop, described by the key it
enforced. The widening arm (PR #32356) is untouched.
This is the answer the other two arms already give an unresolved
carrier, and the one `SqlDriver.resolveHashShadowKeys`' docblock
promises ("`diffManagedIndexes` then reports NOTHING for it ... The
degraded outcome is a missing finding, never a dropped constraint").
Before this change the orphan arm broke that promise.
## Why
`isHashShadowCarrier` recognises a carrier by name alone, so it holds
even when the generation expression cannot be read, and its jsdoc rules
that a carrier "is never a thing this differ may propose destroying on a
guess". PR #32356 applied that to the widening arm; the redefinition arm
already had it. The orphan arm had no such exemption, so an unresolved
carrier under any other generated name (a retired declaration, or a
tenant-arm legacy name, which claims no carrier) was offered as
`drop_index`, `destructive`. An operator running `os migrate apply
--allow-destructive` would drop a unique constraint whose key nobody had
read.
## Tests
All in
`packages/drivers/driver-sql/src/sql-driver-13015-shadow-carried-index-drift.test.ts`,
the shared harness for shadow-carried index drift, as one new top-level
`describe` plus one live cell (no new file):
- An unresolved carrier no declaration names: no entry of any kind. In
the same call, two colocated CONTROLs: a RESOLVED orphan carrier is
still `unmapped_index` / `drop_index` / `destructive`, described as
`UNIQUE (organization_id, gone)`, and the ordinary drifted unique is
still `recreate_index`.
- Outside the widening arm: an unresolved carrier under a tenant-arm
legacy name (no `widenedBy`) is kept; the whole diff is empty.
- CONTROL: the same carrier with its key read is still the orphan
`drop_index`.
- The widening arm's unresolved-carrier answer from PR #32356 is
unchanged (kept, nothing offered).
- Live MySQL cell: two retired shadow-carried UNIQUEs built by
`initObjects`; one shadow is rebuilt with a generation expression that
names no column (`UNHEX(SHA2('unreadable', 256))`), which
`resolveHashShadowKeys` resolves to nothing. A fresh driver with neither
declared: the resolved one is offered as `drop_index`, the unreadable
one is not; after `applyMigrationEntries(drift, { allowDestructive: true
})` the catalog still holds the unreadable index and no longer holds the
resolved one.
## Acceptance notes
- **"Kept and reported".** The card's expected text says the carrier is
"kept and reported", and also that this is "the widening arm's answer
after PR #32356". The widening arm's answer is kept with nothing in the
plan, and so is the redefinition arm's; no report-only finding exists
for an unresolved carrier on any arm (`DriftOp` has none, and
`resolveHashShadowKeys` documents "reports NOTHING"). This PR gives the
orphan arm exactly the widening arm's answer and adds no new finding
kind. A report-only entry would be a new `DriftOp` member, an exported
shape the CLI renders; it is named in the seat report as an open
question, not built here.
- **The trade.** A carrier whose declaration really is gone and whose
key cannot be read is no longer listed at all, so its STORED generated
column stays until the key is readable again. That is the same
missing-finding trade the redefinition arm makes, chosen over a guessed
drop.
- **Overlap.** Open PR #32306 also edits `schema-drift.ts`, in the
widening arm (section 1); this hunk is in section 3 only. Whichever
merges second merges `origin/main` first.
## Verification
Measured on `origin/main` `7d82b2dab` + this branch (head `1ead60236`),
with a live MySQL 8.0.46 (`mysql:8.0`, the image CI's live job uses) in
this container.
<details><summary>Red first, on unfixed main (live MySQL
8.0.46)</summary>
The card's first step: an unreadable carrier does reach the orphan arm
on a live server. On `7d82b2dab` with only the new tests added,
`OS_TEST_MYSQL_URL=… vitest run
src/sql-driver-13015-shadow-carried-index-drift.test.ts`: `Tests 3
failed | 13 passed (16)`, live mysql RAN. The live cell's subject
assertion received:
```
"kind": "unmapped_index", "category": "destructive",
"actual": "UNIQUE (uniq_os32399_orphan_unreadable__hash)",
"op": { "type": "drop_index", "indexName": "uniq_os32399_orphan_unreadable", ... }
```
The two pure-function subject pins failed the same way; every CONTROL
and every pre-existing test passed. (A MariaDB 11.8 run was tried first:
MariaDB keys a long TEXT unique natively and takes no shadow route, so
the shadow cells, the pre-existing #13015 ones included, do not apply
there.)
</details>
<details><summary>Green</summary>
- The new file plus `sql-driver-widened-grant-key.test.ts` (the PR
#32356 pins) and
`sql-driver-13056-orphan-shadow-column-cleanup.test.ts`, live MySQL:
`Test Files 3 passed (3)`, `Tests 49 passed (49)`, VERDICT `command-exit
0`.
- `pnpm --filter @objectstack/driver-sql test` (no live URL): `Test
Files 250 passed | 13 skipped (263)`, `Tests 4229 passed | 228 skipped
(4457)`, VERDICT `command-exit 0`.
- `pnpm --filter @objectstack/driver-sql run typecheck`: exit 0 (`tsc
--listFiles` includes the test file).
</details>
<details><summary>Ablation (once)</summary>
`node scripts/ablation-replace.mjs` on the committed head replaced the
new guard line with a marker comment (anchor 1 → 0, blob `08055dc8f89c`
→ `c063c9a460c2`), live MySQL: `Tests 3 failed | 13 passed (16)`, the
three subject pins (pure unresolved orphan, tenant-arm legacy name, live
cell); every CONTROL and the widening-arm pin stayed green. Restored by
the tool: blob back to `08055dc8f89c`, `git diff HEAD` empty.
</details>
<details><summary>Gates</summary>
On `1ead60236` (the final tree; `git merge origin/main` before opening:
already up to date at `7d82b2dab`):
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 66 commands over the 3 changed paths
(200 changed lines, under the 3000 threshold). Each was run with its
exit code recorded before any pipe.
- First pass: 62 exited 0, 4 exited 3 (PREREQUISITE NOT MET, not
findings): `check-plugin-teardown-shape --self-test` (its fixture commit
was outside this shallow clone; the commit was fetched), and
`check:dual-build-cjs-loads`, `check:lean-entry-closure`,
`check:type-check-debt` (they read built output of packages outside
driver-sql's closure; `pnpm turbo run build --concurrency=2`, 120 of 120
tasks, VERDICT `command-exit 0`). All four re-run: exit 0.
- `node scripts/pm/dispatch-gates.mjs --ran`: **66 derived, 66 run, 0
NOT-MEASURED, 0 UNRUN**, exit 0.
- `pnpm lint` (repo-wide `eslint . --no-inline-config`): exit 0. eslint
over the two touched source files: exit 0.
</details>
**NOT MEASURED here:** MariaDB with a shadow carrier (MariaDB takes no
shadow route for this shape, see above); the full dogfood battery (no
`!` title and no `(narrowing)` arm).
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No spec change.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (Repo-wide `pnpm lint`:
exit 0.)
- [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. (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. (`## 维护者速读` is the
maintainer's Chinese summary the dispatch rules ask for.)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Utp6CamgV1EYRYcyP8yQ5h
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CamgV1EYRYcyP8yQ5h)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent ba8e993 commit 76684a7
3 files changed
Lines changed: 200 additions & 0 deletions
File tree
- .changeset
- packages/drivers/driver-sql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3113 | 3113 | | |
3114 | 3114 | | |
3115 | 3115 | | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
3116 | 3126 | | |
3117 | 3127 | | |
3118 | 3128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
0 commit comments