Commit d0e43af
fix(migrate,runtime,tanstack): six bugs found by a downstream D1/uuid adopter
All six reported against 0.15.20 and confirmed on main; failing tests written
first for each. Three turned out worse than reported.
migrate-ts — data integrity (the dangerous ones):
1. uuid-identity PK's synthesized DEFAULT was diffed as an ordinary default, so
EVERY uuid-PK table drifted on EVERY run with zero metadata changes. The
emitter synthesizes the DEFAULT at DDL time (sqlite/d1
`lower(hex(randomblob(16)))`; postgres `gen_random_uuid()`) and expected-schema
deliberately never records it (uuid generation is modeled as `identity`), but
introspection reads it back as a real expr default — so the two always
disagreed. On SQLite/D1 that false positive is DESTRUCTIVE, not just noisy:
with no ALTER COLUMN, the recreate-and-copy path rebuilt the whole table
(CREATE __new_x / INSERT SELECT / DROP / RENAME) for every already-migrated
uuid-PK table, on every incremental migrate. NOT SQLITE-ONLY as reported:
postgres emits a bogus ALTER every run too — the guard is dialect-agnostic.
2. D1 introspection didn't exclude Cloudflare/wrangler infrastructure tables.
`_cf_METADATA` appears the moment any write touches a local D1, and D1's
authorizer then denies even pragma_table_info against it (SQLITE_AUTH) — since
readTableInfo runs per enumerated table, this ABORTED every second-and-later
`meta migrate --dialect d1` (invisible until the first incremental run, because
the first migration is the write that creates it). `d1_migrations` is
queryable, so it merely read as an undeclared "extra" table — and the diff
proposed DROP TABLE on wrangler's own bookkeeping. Filter in the query, so
`_cf_METADATA` is never even fetched.
3. SQLite quoted every literal default regardless of column type, so
`field.boolean @default false` emitted `DEFAULT 'false'` on a NUMERIC-affinity
column. SQLite cannot coerce that, stores TEXT, and `col = 0` then silently
misses the row (verified against real sqlite3). Numeric defaults hit the same
path but were merely invisible — affinity coerces a numeric-looking '0', which
is exactly why this sat unnoticed. Defaults are now rendered per the column's
SQL type (boolean -> unquoted 1/0; numerics unquoted; text still quoted and
escaped; non-numeric junk on a numeric column falls back to quoting).
An existing golden had PINNED the buggy shape; updated with the reason, after
proving the new output correct in real SQLite. Postgres is left as-is
deliberately: it casts a quoted literal at DDL-parse time, so it is not
producing wrong data, and churning its DDL output would be risk for no gain.
runtime-ts — a server-side runtime bug:
4. The read-only (projection) mounts coerced the GET-by-id path param through
`Number(id)` unconditionally, so any uuid/text PK 404'd for every id that
actually exists — the row is right there in the same projection's list
response, but its own detail route can never find it (with libsql it throws
outright). AFFECTED BOTH MOUNTS, hono and drizzle-fastify, not just hono.
Root cause is tidy: runtime-ts already has `parseId`, used by every WRITABLE
mount; only the read-only ones bypassed it. Added a column-aware
`coerceIdForColumn` (reads the PK's real `dataType` off the Drizzle column, so
existing generated code is fixed with no regen and no option change) plus
`rawIdLiteral` for the raw-SQL view path, which previously 400'd a perfectly
valid uuid.
codegen-ts-tanstack — wrong generated types:
5. The hooks template hardcoded `id: number` at every emission site, so a uuid PK
generated hooks typing the key as a number while the row's real id is a string
— a genuine tsc error at every consumer call site. `getPkInfo(entity, ctx)`
already existed and is used correctly by the queries template; the hooks
template just never called it. Threaded through all three render paths
(read-only, writable, TPH) — more sites than reported, including the bare
`number` delete-mutation variable types.
6. The grid-hook template's `sorting[0].id` failed `noUncheckedIndexedAccess`
(a `.length > 0` guard doesn't narrow an index access). Fixed with real
narrowing rather than a non-null assertion; goldens regenerated after
confirming the diff is exactly that and semantically identical.
Full suite 5056 pass / 0 fail; typecheck clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hd5NWZ1rKau63vJzrBSpLb1 parent 92709fb commit d0e43af
18 files changed
Lines changed: 641 additions & 54 deletions
File tree
- server/typescript/packages
- codegen-ts-tanstack
- src/templates
- test
- fixtures
- golden/__snapshots__
- grid-filter
- multi-grid
- single-entity
- migrate-ts
- src
- diff
- emit
- introspect
- test/unit
- runtime-ts
- src
- drizzle-fastify
- hono
- test
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
Lines changed: 26 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
| |||
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
179 | | - | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | 188 | | |
185 | | - | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
225 | 232 | | |
226 | 233 | | |
227 | 234 | | |
| |||
254 | 261 | | |
255 | 262 | | |
256 | 263 | | |
257 | | - | |
| 264 | + | |
258 | 265 | | |
259 | 266 | | |
260 | 267 | | |
261 | 268 | | |
262 | 269 | | |
263 | | - | |
| 270 | + | |
264 | 271 | | |
265 | 272 | | |
266 | 273 | | |
| |||
308 | 315 | | |
309 | 316 | | |
310 | 317 | | |
311 | | - | |
312 | | - | |
| 318 | + | |
| 319 | + | |
313 | 320 | | |
314 | 321 | | |
315 | 322 | | |
| |||
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
330 | | - | |
331 | | - | |
| 337 | + | |
| 338 | + | |
332 | 339 | | |
333 | 340 | | |
334 | 341 | | |
| |||
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
362 | 372 | | |
363 | 373 | | |
364 | 374 | | |
| |||
399 | 409 | | |
400 | 410 | | |
401 | 411 | | |
402 | | - | |
| 412 | + | |
403 | 413 | | |
404 | 414 | | |
405 | 415 | | |
406 | 416 | | |
407 | 417 | | |
408 | | - | |
| 418 | + | |
409 | 419 | | |
410 | 420 | | |
411 | 421 | | |
412 | 422 | | |
413 | 423 | | |
414 | 424 | | |
415 | | - | |
| 425 | + | |
416 | 426 | | |
417 | 427 | | |
418 | 428 | | |
| |||
459 | 469 | | |
460 | 470 | | |
461 | 471 | | |
462 | | - | |
| 472 | + | |
463 | 473 | | |
464 | 474 | | |
465 | 475 | | |
| |||
490 | 500 | | |
491 | 501 | | |
492 | 502 | | |
493 | | - | |
494 | | - | |
| 503 | + | |
| 504 | + | |
495 | 505 | | |
496 | 506 | | |
497 | 507 | | |
| |||
509 | 519 | | |
510 | 520 | | |
511 | 521 | | |
512 | | - | |
513 | | - | |
| 522 | + | |
| 523 | + | |
514 | 524 | | |
515 | 525 | | |
516 | 526 | | |
| |||
Lines changed: 43 additions & 0 deletions
| 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 | + | |
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
Lines changed: 72 additions & 0 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
269 | 279 | | |
270 | 280 | | |
271 | 281 | | |
| |||
0 commit comments