Repository navigation
fix(drivers): retire the activation ledger's old two-part unique on upgraded MongoDB and MariaDB databases - #31831
Conversation
…pgraded MongoDB and MariaDB databases driver-mongodb gains a widening arm in schema sync (create-before-drop, guard required for a nullable gained field). driver-sql reads a row-scoped hash shadow (CASE WHEN col IS NULL THEN digest END) as a partial unique on its key parts. metadata-protocol builds the package-less guard on MariaDB as an INVISIBLE generated carrier column plus a UNIQUE key. Claude-Session: https://claude.ai/code/session_01ADHkmRrVsZDvnixDwxnpGN Co-authored-by: Claude <noreply@anthropic.com>
…rd and its migration arm; add the changeset Claude-Session: https://claude.ai/code/session_01ADHkmRrVsZDvnixDwxnpGN Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check25 anchor(s) derived from 3 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 23 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 854b8a56144aaa50ae742008249dc1f2b670aa40 && git checkout 854b8a56144aaa50ae742008249dc1f2b670aa40
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin ad622d30f6589c7b1f104f55bc3caf1a4d4894dd 5bd9735277784c115b2a2b4faf3b9a395111644b && git checkout -B drift-repro ad622d30f6589c7b1f104f55bc3caf1a4d4894dd && git merge --no-ff 5bd9735277784c115b2a2b4faf3b9a395111644b
node scripts/docs-audit/affected-docs.mjs --json ad622d30f6589c7b1f104f55bc3caf1a4d4894dd |
|
epic:#31527#1 · os-steve · session_01ADHkmP7o3uDTti21wLTfPf Epic red-line review: #31732, head f28a8b8 · 2026-11-09T06:04Z Verdict: PASS. Package-less one-row is enforced by the store on every dialect at every moment, every index change is create-before-drop, and no index outside the declared one is dropped.
With this landed, #31732's precondition for E children is met: a second package's ledger row is admitted on every dialect that has a guard, and refused where none exists. Seat 4 accepts and lands after green CI. It is not a governed surface. |
Claude-Session: https://claude.ai/code/session_01ADHkmRrVsZDvnixDwxnpGN Co-authored-by: Claude <noreply@anthropic.com>
|
domain:server#4 · os-steve · session_01ADHkmP8JJo4zF2sjTBRwnX ACCEPT · PR #31831 · #31732 · 2026-11-09T06:55ZHead-sha:
|
Requested by Steve · project thread
Fixes #31732
Clause-②: no
Metadata-protocol: none
维护者速读
os migrate plan会把旧索引报成安全替换。(metadata_type, package_id, name),但这两种升级来的库会留着旧的两段索引,史诗后续子卡第一次写第二个包的同名行就会被拒。本卡要在那之前把它安全换掉。packages/drivers/driver-mongodb/src/mongodb-schema.ts的retireWidenedUniques、packages/metadata-protocol/src/migrations/activation-ledger-packageless-index.ts的 MariaDB 分支、packages/drivers/driver-sql/src/schema-drift.ts的parseHashShadowRowScope。pnpm --filter @objectstack/driver-mongodb exec vitest run src/mongodb-activation-ledger-packageless.test.ts,预期 10 条通过(另 4 条真实 mongod 用例需OS_TEST_MONGODB_MEMORY_SERVER_ENABLED=1)。What changes
driver-mongodb,retireWidenedUniques). After the create loop, schema sync drops a unique an earlier declaration built once a declared key has widened it. It mirrors driver-sql'swidenedUniqueReplacementsand is create-before-drop. Every condition is required:unique: trueor'global', with 2 to 8 fields;idx_<fields>_unique);uniqueis built as a sparse index, so two explicitnullvalues collide, unlike the NULL-distinct rule of driver-sql and driver-memory #29278) or the sparse shape before it, never an index with other options;required, a partial unique on exactly the narrower fields stands, whose filter tests each such field fornull. The ledger's guarduniq_sys_metadata_activation_packagelessis built in the same loop. Without it the old index is KEPT.warnline per retired index names the collection, the old key and the new key. The plain read index over the old fields stays: it refuses nothing, and the planner still answers the ledger's(metadata_type, name)lookup with it (measured).syncCollectionSchematakes an optional{ logger }; the default writes throughconsole.warn, asSqlDriver's default logger does. It is not exported from the package root.metadata-protocol,ensureActivationLedgerPackagelessIndex). MariaDB refuses both S1 forms (partialWHEREand functional key part,ER_PARSE_ERROR, measured on 11.8). The guard there is oneALTER TABLE: an INVISIBLE generated columnuniq_sys_metadata_activation_packageless__hash VARBINARY(32) AS (CASE WHEN package_id IS NULL THEN unhex(sha2(concat(metadata_type, 0x1f, name), 256)) END) VIRTUAL INVISIBLE, plusUNIQUE KEY uniq_sys_metadata_activation_packagelessover it.SELECT VERSION(). An unreadable version takes the MySQL form, as before.ER_DUP_FIELDNAME; the migration then adds the key alone, andER_DUP_KEYNAMEreads as in place.ER_DUP_ENTRY, reported asconflictwith the listing query, and nothing is deleted (the S1 path).schema-drift.ts,sql-driver-introspection.ts). The carrier column is named as a driver-sql (MySQL): full-value UNIQUE on >768-char token columns is inexpressible on utf8mb4 — hash-shadow-key route for the four ruled cases (C half of the #11374 ruling) #11627 hash shadow (hashShadowColumnFor: index name +__hash), so the orphan-column pass already leaves it alone. On the S1 tree the index itself read as a DESTRUCTIVE orphandrop_indexkeyed(package_id, metadata_type, name), and the old two-part index stayed KEPT (measured). Now:parseHashShadowRowScopereads acase when <col> is null then <digest> endexpression's scope column.parseHashShadowKeyPartsreturns the digest's parts alone, so every reader (the differ, the duplicate decorator, the shadow-state check) sees(metadata_type, name).resolveHashShadowKeysmarks such a carrierpartial: true. A partial index is runtime-managed (isSyncReproducibleIndex), so it is never an orphan.hasPartialUniqueGuardcompares the enforced key (enforcedIndexKey), so the carrier counts as the widening arm's guard. The old index then reads as onereplace_unique_index, category safe, exactly as on SQLite and PostgreSQL.Why
S1 (#31727) widened the ledger's unique key to
(metadata_type, package_id, name). Two kinds of upgraded database keep the old(metadata_type, name)unique beside it:There, the first row a second package writes under an existing name is refused (
E11000orER_DUP_ENTRYon the old index). The epic's later child cards write exactly those rows. This PR retires the old index safely before they land, and the package-less "one row per item" rule stays enforced by the store throughout.Step 0 (measured on
main5b7269f, Docker in the card container: MariaDB 11.8.9, mongod 8.0.34)idx_metadata_type_name_uniquestands beside the new key and the guard; a second package's row of a name is refusedE11000on the old index (package-less, alpha, beta all refused)WHERE/ functional key partER_PARSE_ERRORbothSELECT *anddriver.find; drift on the S1 tree: one destructive orphandrop_indexon the guard, old index still keptTests
driver-mongodbmongodb-activation-ledger-packageless.test.ts(shared harness file, new top-level describes):Db, every lane, 8 cases: upgraded collection retires the old unique after both creates, with one log line naming collection, old key and new key; the pre-driver-mongodb: fielduniqueis built as a sparse index, so two explicitnullvalues collide, unlike the NULL-distinct rule of driver-sql and driver-memory #29278 sparse shape retired too; CONTROL fresh collection (nothing dropped, no log); CONTROL narrower unique still declared (kept); nullable gained field with no guard (kept); required gained field (retired); a same-name index this driver did not build, or a wider key not present (kept); a named declaration (claims nothing).MongoDBDriver; old unique gone, new key + guard + read index stand; package-less second row refused, two packages admitted, one package twice refused.driver-sqlsql-driver-widened-declared-unique.test.ts(shared harness file): 4 pure cases (the scope and key parts of MariaDB's stored expression, an ordinary shadow unchanged, the row-scoped carrier counts as the guard, an unscoped carrier does not), plus a live MariaDB cell (MYSQL_CELL, skipped on MySQL withctx.skip): upgraded table, plan = one safe replace and nothing else, apply with noallowDestructive, re-plan empty, refusals asserted asER_DUP_ENTRYnaming the index, the carrier absent fromdriver.findandSELECT *, a second boot draws no drift.metadata-protocolactivation-ledger-packageless-index.test.ts: new describe, 6 cases (carrier name = driver-sql's shadow name, the exact statement, MariaDB takes it and never the MySQL statement, second boot re-key path, conflict, MySQL still takes its functional form).activation-ledger-packageless-index.test.ts: the case titled "a dialect with neither form (MariaDB) is unsupported" is retitled "a server with no form at all (MySQL before 8.0.13, version unreadable)". Its body is unchanged: MariaDB is no longer that case.activation-ledger-packageless-index.live-dialects.test.ts: the MySQL/MariaDB case assertedunsupportedon MariaDB. It now assertscreatedon both and, on MariaDB, that the carrier is absent fromSELECT *. The header line saying MariaDB builds nothing is corrected.mongodb-activation-ledger-packageless.test.ts: the shared mongod is stopped once in a module-levelafterAllinstead of in the first real-server describe's, so the second real-server describe can use it.Acceptance notes
SELECT VERSION()read before it). Its old index is a hash-shadow carrier that the widening arm never claims (S1's reading, untouched here).unsupported, and keeps the old index (the S1 behaviour).schema-drift.tsandsql-driver-introspection.ts; the package-less migration; tests; the changeset).Verification
Head f28a8b8 on base 5b7269f (S1's merge). Live servers ran in Docker in the card container: MariaDB 11.8.9, MySQL 8.4.13, mongod 8.0.34.
activation-ledger-package-key,activation-ledger-actor,packaged-activation-ledger-reach,upgrade-18x-harness,upgrade-18x-index-equivalence.showcase_invoiceschema-sync error lines in that log are sqlite-wasm's non-constant default, which this PR does not touch.pnpm build: 119 of 119 tasks.check:dual-build-cjs-loads: green (122 entries, 72 packages).check:driver-conformance: 66 covered, 6 DEBT on head, and the same 66 and 6 on base.--no-inline-config): exit 0. None of the three has alintscript of its own (pnpm --filter … lintanswersERR_PNPM_RECURSIVE_RUN_NO_SCRIPT).dispatch-gates --ran: 69 derived, 69 run, each with its exit code, 0 NOT-MEASURED.Ablations (
scripts/ablation-replace.mjs; each was red, then restored withgit diff HEADempty):partialSELECT *keysER_DUP_FIELDNAMErethrownHuman Minimum
Nothing; the seat reviews and lands. The PR is draft.
🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmRrVsZDvnixDwxnpGN