Repository navigation
Commit 88ae2f9
fix(driver-sql): a plain index MySQL refuses to key no longer skips the object's remaining boot steps (#38225)
Part of #35862 — this lands the card's half (B), the bounded one it
orders first. Half (A) stays open on the card: converging an old MySQL
TEXT column to its declared varchar(n), then the inbox index itself,
which this dispatch excluded (it belongs to the other half of #35530).
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:使用 MySQL 的部署里,某个对象声明的普通(非唯一)索引如果落在旧的长文本列上,MySQL
会拒建;以前这会让该对象每次启动都跳过后续的数据修复步骤并报"同步失败",现在只记一条错误日志、其余步骤照常跑完。PostgreSQL 与
SQLite 用户无感。
- 为什么做:这是收件箱铃铛提速(给消息表加按用户和时间的索引)的前置一半,先保证这类索引被拒时不再连带丢掉别的启动步骤。
- 出错会怎样:被拒的索引依旧不建、不做替代,日志照常报出并给出手工改列的办法;本改动可以直接撤回,撤回后回到原先"抛错并跳过后续步骤"的行为。
- 要你做什么:另一半(把旧文本列收敛成定长列,再上收件箱索引)走哪条路需要你定,见下方 Acceptance notes 第一条。
## What changes
- `syncDeclaredIndexes`
(`packages/drivers/driver-sql/src/sql-driver-schema-sync.ts`): when
MySQL refuses to key a PLAIN index (`ER_BLOB_KEY_WITHOUT_LENGTH` or
`ER_TOO_LONG_KEY`, the codes `explainUnkeyableTextColumn` recognises),
the refusal is still logged once at `error` through
`logDurabilityFailure` with the same field-level remedy, and the loop
now `continue`s instead of throwing. The index is still not created and
still not substituted: no prefix index, no hash shadow (the existing
scope limit for non-unique indexes).
- What the throw used to cost, measured on live MySQL 8.0.46 before the
fix: `initObjects` rejected for the object, so every index declared
after the refused one was never attempted, and
`retireIndexesNamedForOldKeys`, `reconcileAndWarnDrift`, the four
canonical backfills and `migrateMysqlDatetimeColumns` /
`migrateMysqlTimeColumns` never ran for that table, on every boot.
- Unchanged on purpose: a UNIQUE index that the hash-shadow route could
not carry still throws (the card's CONTROL). PostgreSQL and SQLite never
raise these codes, so their path is byte-identical.
- Why the fix sits in the producer and not in a catch in `initObjects` /
`syncTableIndexes`: the throw is the defect; a catch further up would
still lose every index after the refused one in the same loop, and would
also swallow the UNIQUE case the card keeps.
## Tests
- New `sql-driver-35862-refused-plain-index-boot-steps.test.ts`:
- everywhere (SQLite): the MySQL refusal faked at
`knex.schema.alterTable` with MySQL's own error shape, for both codes.
Pins: one `error` line naming the object and the index; the refused
index absent; the index declared after it built; every later boot step
(8 named) called for the table; the drift report's warn line present.
CONTROL: the same refusal on a UNIQUE index still rejects with `code:
'ER_BLOB_KEY_WITHOUT_LENGTH'` and the named refusal.
- every dialect cell (SQLite, live PostgreSQL, live MySQL): the real
upgrade, a TEXT `user_id` from the release before the bound, then the
release that declares `maxLength: 255` and a plain `(user_id,
created_at)` index plus a `seen_at` index. On MySQL: the column is still
TEXT (the premise), the plain index is absent with no shadow column, one
error line, the `seen_at` index built, and a legacy `TIMESTAMP`
`seen_at` widened to `datetime(3)` (the last step `initObjects` runs).
CONTROL on PostgreSQL and SQLite: the index is built directly, no error
line.
- live MySQL CONTROL: a UNIQUE index over a `maxLength: 1024` text
column is still carried on a hash shadow (whole key part, `SUB_PART`
null, `NON_UNIQUE` 0).
- Rewritten, not deleted: three live MySQL pins asserted `initObjects`
REJECTS for a non-unique unkeyable index
(`sql-driver-11627-hash-shadow-key.test.ts` one,
`sql-driver-keyed-text-mysql.test.ts` two). They pinned exactly the
throw this change removes; they now read the same named refusal from the
`error` channel and keep their negative half (no index keys the column,
no shadow column).
- In CI the live cells run in `Temporal Conformance (live PG + MySQL)`,
step "Run driver-sql suite against both live servers" (it runs this
whole package with `OS_TEST_MYSQL_URL` and `OS_TEST_POSTGRES_URL` set
and `OS_EXPECT_LIVE_DIALECT_MATRIX=1`). The SQLite layer also runs in
`Test Core`.
## Acceptance notes
- Fork left for the maintainer, half (A): the card's own Expected
section asks for a keyed TEXT column to converge to its declared
varchar(n) on MySQL, "either schema sync or an `os migrate` arm",
refusing with the offending rows named when a stored value is longer
than n. That choice is open, and neither alternative named in the
dispatch fits: a hash shadow is ruled out for non-unique indexes by the
existing scope limit (a digest serves no lookup), and a prefix index is
a valid access path for a plain index but is not what the card asks for.
No code for (A) is in this PR.
- The refusal line `explainUnkeyableTextColumn` writes ends with "so any
uniqueness it declared is currently unenforced" and a sentence about
UNIQUE prefix indexes; on a plain index both are true but beside the
point. Left as is: the line is shared with the UNIQUE path.
- After the refusal the drift report warns that the index is missing and
says to run "os migrate apply" to create it; on MySQL that apply meets
the same refusal and reports the index as not applied (the create op
checks presence). Existing wording, not changed here.
- `SqlDriver#syncDeclaredIndexes`'s docblock in `sql-driver.ts` lists
the dispositions; a bullet for this one would push the facade over its
line ceiling (`check:facade-delegation-only`, 10071 lines, 0 left), so
the disposition is documented at the body in `sql-driver-schema-sync.ts`
instead.
## Verification
Read first, by risk:
1. `packages/drivers/driver-sql/src/sql-driver-schema-sync.ts`, the new
`if (!unique)` arm after `this.logDurabilityFailure(unkeyable, msg)`:
the only behaviour change.
2.
`packages/drivers/driver-sql/src/sql-driver-35862-refused-plain-index-boot-steps.test.ts`,
the `refuseIndexes` fake: it decides the refusal from the index the
`alterTable` callback declares, and passes everything else to the real
knex.
3.
`packages/drivers/driver-sql/src/sql-driver-keyed-text-mysql.test.ts`,
the two rewritten pins.
Two-minute check: `pnpm --filter @objectstack/driver-sql exec vitest run
sql-driver-35862` prints `Tests 4 passed | 3 skipped (7)` with no server
(the 3 skipped are the live PostgreSQL and MySQL cells); with
`OS_TEST_MYSQL_URL` and `OS_TEST_POSTGRES_URL` set it prints `Tests 7
passed (7)`.
Readings, all at head `f1c4549df3`, on local MySQL 8.0.46 (server zone
+08:00) and PostgreSQL 16 (Asia/Shanghai), process
`TZ=America/New_York`, `OS_EXPECT_LIVE_DIALECT_MATRIX=1`:
<details><summary>The three touched files on live MySQL + PostgreSQL:
26/26</summary>
`vitest run sql-driver-35862 sql-driver-11627-hash-shadow-key
sql-driver-keyed-text-mysql`: `Test Files 3 passed (3)`, `Tests 26
passed (26)`.
</details>
<details><summary>Ablation: the fix removed, 6 red and every CONTROL
green</summary>
`scripts/ablation-replace.mjs` replaced the anchor `if (!unique) {` with
`if (false) {` (anchor 1 to 0, blob 3fbbf2d to c0aaa9b00fb7) and
ran the same three files: `Tests 6 failed | 20 passed (26)`. Red: both
faked refusals, the live MySQL upgrade (it rejected with
`ER_BLOB_KEY_WITHOUT_LENGTH` on `idx_os35862_inbox_user_id_created_at`,
which is the card's premise, measured), and the three rewritten pins.
Green: the UNIQUE CONTROL, the PostgreSQL and SQLite upgrade CONTROLs,
the live hash-shadow CONTROL. Restored: blob equals HEAD (3fbbf2d),
`git diff HEAD` empty.
</details>
<details><summary>Whole driver-sql suite: 7052 passed, 1 failed, both
failing files environmental</summary>
`pnpm --filter @objectstack/driver-sql exec vitest run --maxWorkers=2`:
`Test Files 2 failed | 283 passed | 1 skipped (286)`, `Tests 1 failed |
7052 passed | 12 skipped (7065)`. The two files:
`sql-driver-37095-pgvector-extension` (the local PostgreSQL has no
pgvector extension; CI uses the pgvector image) and
`sql-driver-11565-row-byte-budget` "reports InnoDB page-limit refusals"
(fails identically with the fix ablated, so it is this local server, not
this diff). `pnpm --filter @objectstack/driver-sql typecheck`: exit 0.
</details>
<details><summary>Derived gate families: 67 exit 0, 2 not
measured</summary>
`dispatch-gates.mjs --commands` (5 paths vs merge base 7605e0c)
derived 69; all run; `--ran` reconciliation: 67 run, 2 NOT MEASURED. The
two are `check:dual-build-cjs-loads` and `check:lean-entry-closure`,
both exit 3 PREREQUISITE NOT MET (they read built output of the whole
workspace, not built here); CI runs them.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent f66cd5a commit 88ae2f9
5 files changed
Lines changed: 437 additions & 16 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 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
299 | 303 | | |
300 | 304 | | |
301 | 305 | | |
| 306 | + | |
| 307 | + | |
302 | 308 | | |
303 | 309 | | |
304 | 310 | | |
305 | 311 | | |
306 | 312 | | |
307 | | - | |
308 | | - | |
309 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
310 | 318 | | |
311 | 319 | | |
312 | 320 | | |
| |||
| 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 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
0 commit comments