Repository navigation
Commit 69949ae
fix(driver-turso): the REMOTE face relaxes a NOT NULL column in place with libSQL ALTER COLUMN, applied only on a read-back (#34408)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XHBgb29oZuAnPqZyY6nR8UE)_
Part of #33724
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:托管库(Turso 远程连接方式)上,"去掉一列的不能为空"现在真的会执行:用 libSQL 自带的改列语句就地改这一列,只删掉
NOT NULL 这几个字,不搬数据、不重建表。
- 为什么改:应用包升级把必填字段改成选填后,托管客户的数据库还在拒绝空值,保存全部失败;裁决 6915086281 选 A(就地改这一列),本
PR 是框架半边。
-
风险与回滚:只放宽不收紧;语句和"表定义必须恰好变成预期样子"的检查放在同一批里,任何意外整批回滚、表一字不变;读回确认才算成功。已知限制(裁决
6922037129,接受):列定义里带逗号的列(DEFAULT 或 CHECK 里有逗号、`NUMERIC(10, 2)`
这类宽度、注释)托管库改不了,保持必填,apply 列为未应用,日志写明"定义里有逗号",不重建表;平台自己建的列不带逗号,不受影响。回滚 =
revert 本 PR,托管上回到"跳过"。
-
先看:`packages/drivers/driver-turso/src/turso-driver.ts`(`applyRemoteRelaxNotNull`,批内检查、读回与失败时的日志)、`packages/drivers/driver-turso/src/remote-relax-not-null.ts`(从库里存的建表语句切出这一列的定义)、`turso-remote-migration-entries.test.ts`
的 relax 一组。
- 两分钟验证:`pnpm --filter @objectstack/driver-turso exec vitest run
src/turso-remote-migration-entries.test.ts`,预期 18 条全绿,其中 relax 5
条(已应用、逗号被拒且日志点名、提交后传输出错记为结果未知、意外拼接回滚、安装门已应用)。
- 需要你做的:无,席位落地(真实 sqld 0.24.33 已实测:两份门控文件 2/2、9/9)。
## What changes
The maintainer's ruling on #33724 (record 6915086281, letter A): the
Turso REMOTE face relaxes a NOT NULL column in place with libSQL's own
`ALTER TABLE t ALTER COLUMN c TO c DEFINITION`, and runs no table
rebuild.
- `REMOTE_DRIFT_OP_ANSWERS.relax_not_null`: `'needs-table-rebuild'`
becomes `'applied'`. It is the one declaration both the apply door and
`driftApplyLimit` (what `os migrate plan` reads) dispatch by, so the
plan now lists a remote relax with no transport limit.
`tighten_not_null`, `drop_column_default`, the widths and
`widen_date_to_datetime` keep `'needs-table-rebuild'` (ruling parameter
1).
- `TursoDriver.applyRemoteRelaxNotNull` (new, private), reached from the
REMOTE column drift arm:
- **The definition comes from the database, not from metadata**
(parameter 5). `planRelaxedColumnDefinition` (new module
`remote-relax-not-null.ts`) lexes the table's stored `CREATE TABLE`
(quotes, brackets, both comment forms, nesting) and cuts out the
column's own definition. It removes only `[CONSTRAINT name] NOT NULL [ON
CONFLICT x]` at the definition's own depth and keeps every other byte.
Measured on libSQL: whatever the text after `TO` leaves out is gone from
the column, so a definition rebuilt from `pragma_table_info` would
silently drop a CHECK, a COLLATE, a UNIQUE or a REFERENCES clause.
- **One `write` batch: the statement and a check.** The check is a
SELECT that fails (`json()` over a malformed argument, evaluated only on
the CASE's mismatch arm) unless `sqlite_master.sql` now equals exactly
the planned table SQL. If libSQL splices any other way, the whole batch
rolls back.
- **Applied only on a read-back** (parameter 3). The column then reads
nullable, with the type, the DEFAULT and the pk position it had.
Anything else is `false`, which the apply door reports `skipped`, and
the reason is logged at `warn` (the caller gets the skipped entry).
- **No fall-back** (parameter 4). A refusal is a refusal.
- The doors do not change (parameter 2). `relaxDeclaredNotNull` (the
managed install) and `applyPublishedColumnChanges` (the publish) stay
`inherited`, so they reach this arm through the face's own
`applyMigrationEntries`, as does `os migrate apply`. The REMOTE face
runs no boot reconcile, and a remote sync of the upgraded declaration
leaves the column NOT NULL (pinned).
- The local face is untouched (parameter 6).
- `content/docs/deployment/cli.mdx`: the remote-primary paragraph says
the relax is applied in place, and how a refusal reads.
- Changeset: `@objectstack/driver-turso` patch.
## Tests
- `remote-relax-not-null.test.ts` (new, 10 cases): the planner over the
stored-text shapes a hosted table can hold. These include a
parenthesised DEFAULT, a named constraint with ON CONFLICT, `NOT
DEFERRABLE` and `SET NULL` (not the constraint), `NUMERIC(10, 2)`,
comments, every SQLite quoting, a string that reads `NOT NULL`, and
table constraints. There are refusals for a missing clause, a missing or
doubled column, and unterminated text.
- `turso-remote-migration-entries.test.ts`, over a real libSQL
connection, read back through a second connection:
- The old skip pin at `:290` now pins a `tighten_not_null` as skipped,
with the stored SQL byte-identical.
- The old install pin at `:318` now pins `relaxDeclaredNotNull` as
applied: the column is nullable with the same type and DEFAULT, and a
NULL write succeeds. It also pins that a remote sync of the `notNull:
false` declaration does NOT relax (ADR-0113 D5).
- New: both columns of a hand-made table are relaxed. The stored SQL
loses only the two NOT NULL clauses. Indexes, rows, DEFAULT, CHECK,
COLLATE-backed UNIQUE and `integrity_check` are unchanged, and a re-run
is a no-op.
- New: a DEFAULT with a comma is refused by libSQL. The entry is skipped
and the table byte-identical.
- New: a splice the plan did not predict (the statement altered on its
way out) is rolled back by the in-batch check.
- `turso-remote-drift-apply-limit.test.ts`:
`driftApplyLimit('relax_not_null')` is `null` on the REMOTE face, and
the apply door applies the relax (`memo` reads nullable). This is the
driver half of the `os migrate plan` listing.
- `turso-remote-relax-not-null-sqld.test.ts` (new, skipped unless
`OS_TEST_SQLD_BIN`): FIRST the bare statement on a real `sqld` with a
column read-back and a NULL write, then the install door on a
remote-mode driver with no client of its own. Measured since on official
`sqld` 0.24.33: 2/2 (records 6921391723, 6921439242; Fix round 3 and 4).
## Acceptance notes
- **libSQL's splice, measured** (embedded libSQL, SQLite 3.45.1): libSQL
ends the old definition at the first comma after the column name. A
comma inside a DEFAULT (`('a,b')`, `(strftime('%Y','now'))`), a CHECK, a
width (`NUMERIC(10, 2)`) or a comment makes the spliced `CREATE TABLE`
unparseable, and the statement is refused. Such a column keeps its NOT
NULL and the entry is skipped. Columns this face creates (`TYPE [NOT
NULL]`) have no comma. A real `sqld` 0.24.33 refuses such a column the
same way (record 6921391723); the limit is accepted by ruling 6922037129
(Fix round 4).
- The three pins the change made false outside driver-turso were
rewritten in fix round 1, after claim amendment 6917885070 extended the
file surface (see `## Fix round 1`).
- `relaxInstallDeclaredNotNull` (cloud-connection) is a pass-through to
the driver's `relaxDeclaredNotNull`, which is pinned here. A pin of the
helper itself against a REMOTE-face driver is NOT MEASURED:
cloud-connection has no driver-turso dependency, and the helper's tests
are outside this surface.
## Verification
<details><summary>Targeted tests and typecheck (lock VERDICT
command-exit 0)</summary>
```text
pnpm --filter @objectstack/driver-turso build && pnpm --filter @objectstack/driver-turso typecheck && vitest run (4 files)
Test Files 3 passed | 1 skipped (4)
Tests 33 passed | 2 skipped (35)
tsc --noEmit --listFiles: the four touched test files are in the program (101 test files)
```
</details>
<details><summary>Full driver-turso suite at 342fedf (lock VERDICT
command-exit 0)</summary>
```text
pnpm --filter @objectstack/driver-turso exec vitest run --maxWorkers=2
Test Files 100 passed | 1 skipped (101)
Tests 2562 passed | 36 skipped (2598)
```
</details>
<details><summary>Ablations (one-off, the change committed first,
restored by ablation-replace with blob == HEAD)</summary>
```text
1. the check always passes (= ? THEN 1 -> = ? OR 1 THEN 1):
x a splice the plan did not predict lands nowhere ... (applied instead of skipped)
Tests 1 failed | 16 passed (17); restored blob e91ad7c == HEAD
The read-back alone reported that splice applied: it had dropped the CHECK, which pragma_table_info cannot see.
2. relax_not_null: 'applied' -> 'needs-table-rebuild':
4 failed | 19 passed (23): the drift-apply-limit pin, the in-place relax, the check, the install door
restored blob e91ad7c == HEAD
```
</details>
<details><summary>Derived gates (dispatch-gates --ran: 100 derived, 96
run, 4 NOT-MEASURED, 0 UNRUN)</summary>
```text
96 exit 0, among them check:durability-log-level, check:nul-bytes, check:doc-authoring,
check:issue-citations, check:test-source-alias, check:cross-package-test-inputs, check:driver-conformance
NOT MEASURED: spec check:skill-examples, check:dual-build-cjs-loads (exit 3, prerequisite: unbuilt packages)
NOT MEASURED: check:query-options-erasure, check:type-check-debt (400 s timeout on a shared box; CI owns them)
```
</details>
- The real `sqld` pin (ruling parameter 4's first step), first NOT
MEASURED here, was measured by the maintainer's decision thread on
official `sqld` 0.24.33: 2/2 (6921391723, 6921439242), and rerun on the
final head in Fix round 4. CI has no `sqld`, so CI does not exercise it.
- No open PR touches `packages/drivers/driver-turso` (54 open PRs read),
so there was nothing to `merge-tree` against.
## Fix round 1
Claim amendment 6917885070 extended the file surface to the three pins
outside driver-turso that the ruling makes false. Only tests change
outside `packages/drivers/driver-turso/**`. The `Clause-②` and
`Metadata-protocol` lines are unchanged.
-
`packages/runtime/src/domains/meta-object-publish-column-changes.test.ts`:
the Turso REMOTE describe now pins both halves on the same face.
- The publish relaxes `title` in place, with no
`object-column-changes-not-applied` advisory, and a create that omits
the field succeeds.
- The advisory stays covered by a column the face refuses. Its stored
definition is given a comma by hand, inside a CHECK every row satisfies
(`instr("title", ',') >= 0`). libSQL ends the old definition at that
comma, so the relax is refused, the publish answers the advisory, and
the column keeps NOT NULL.
-
`packages/cli/src/commands/migrate/apply.remote-face.integration.test.ts`
(sqld-gated): the relax names no transport limit, and the plan footer
counts 1 change it cannot apply, not 2. The first apply that confirms
the relax (`--yes`) lands it, so `memo` reads nullable from then on, and
the later cases list only the drop and the tightening. The edit also
added the module-top imports `check:test-source-alias` asks of an edited
test file (seven packages the CLI source imports dynamically).
- `apply.remote-posture.test.ts` and `plan.apply-limit.test.ts`: the
stubbed driver declares a limit for `tighten_not_null` alone and applies
the relax. The relax line carries its finding with no limit, and the
plan footer counts 1.
<details><summary>Round 1 readings (all under the lock)</summary>
```text
Build: --filter runtime^... --filter cli^... --filter driver-turso build -> VERDICT command-exit 0
GREEN at a6797ba:
runtime meta-object-publish-column-changes.test.ts Test Files 1 passed, Tests 5 passed (5)
cli --project unit plan.apply-limit + apply.remote-posture Test Files 2 passed, Tests 24 passed (24)
cli --project integration apply.remote-face.integration Tests 3 passed | 6 skipped (9): the sqld cases skip, no OS_TEST_SQLD_BIN
PREVIOUS behaviour (relax_not_null back to 'needs-table-rebuild', driver-turso rebuilt):
ablation-replace: mutation landed, blob e91ad7c -> 72938d38df31
ablation-dist-preflight: marker present in 2 built files (dist spelling relax_not_null: "needs-table-rebuild")
runtime file: 1 failed | 4 passed (5)
x [#33724] Turso REMOTE: the relax is applied in place ... (the advisory came back)
the refused-relax advisory pin stays green under both behaviours, as it should
restored: blob == HEAD, git diff HEAD empty; dist preflight --absent passes, tree clean
cli stub files: no driver behaviour to ablate (each stub declares its own posture); the sqld file: NOT MEASURED
```
</details>
- Gates for the new paths: `check:route-envelope`,
`check:cross-package-test-inputs`, `check:nul-bytes`,
`check:test-source-alias`, `check:undeclared-dep-imports`,
`check:issue-citations` and `check:doc-authoring` exit 0. `check:i18n`,
`check:i18n-coverage` and `check:i18n-walk-parity` are NOT MEASURED
(exit 3, prerequisite: unbuilt packages); CI ran them in `Lint & Repo
Gates`.
- CI on a6797ba: 38 success, 15 skipped, 0 failure. That includes
Test Core (8/8 shards) and `Lint & Repo Gates`, which was red on
cfc0ab8 at `check:test-source-alias` and is fixed by the imports
above.
- (Superseded by Fix round 3: the real-`sqld` pin is measured, 2/2.)
## Fix round 2
Answers review#2 (contract-review FAIL 6920999561 on `a6797ba0`), items
N1, N2 and N3 only. M1 (the real-sqld pin) and S1 (the comma refusal
class) are with the maintainer and untouched. The docs page and the
maintainer summary are unchanged. Dev report 6921327686 on #33724.
- **N1, the changeset.** It no longer calls `REMOTE_DRIFT_OP_ANSWERS`
exported. It names the published widening as behaviour on the remote
face: `TursoDriver.applyMigrationEntries` now applies a `relax_not_null`
entry, and `TursoDriver.driftApplyLimit('relax_not_null')` answers
`null` where it answered the table-rebuild sentence.
- **N2, a failed batch's outcome.** The catch in
`applyRemoteRelaxNotNull` reads the stored table SQL again before it
logs. If it reads as before the send, the log says nothing landed. If it
no longer reads as before, or cannot be read, the log says the outcome
is unknown and the next drift read decides. The log never says the batch
rolled back.
- **N3, the early return.** A missing column logs `the table has no such
column; nothing was sent`; an already-nullable column logs `the column
is already nullable; nothing was sent`.
- **Pins** (`turso-remote-migration-entries.test.ts`, existing
`logger.warn` spy pattern): the converged re-run asserts the
already-nullable line; the comma refusal asserts `nothing landed`; a new
case commits the real send and then throws `fetch failed: socket hang
up`, and asserts the entry is skipped, the column reads nullable, the
line says the outcome is unknown, and the next drift read finds no relax
left on that column.
- **Ablations:** `now === stored` forced true reddens the
unknown-outcome case; the already-nullable skip replaced by a bare
return reddens the converged case. Both restored to HEAD blobs.
- **Verification on `709476e3`** (under the lock): driver-turso
typecheck passed; targeted files 34 passed, 2 skipped (the sqld file,
M1, not measured); full driver-turso suite 2563 passed, 36 skipped.
## Fix round 3
M1 is closed by the maintainer's real-sqld measurement (record
6921391723 on `a6797ba0`, addendum 6921439242 on `709476e3`): official
`sqld` 0.24.33 accepts the in-place relax, and the driver-turso pin
passes 2/2. That measurement found one wrong expectation in the cli
gated file, and this round fixes only that. S1 (the comma class) waits
for its own ruling. Dev report 6921757949 on #33724.
- **`apply.remote-face.integration.test.ts`, case "apply without
--allow-destructive".** The relax lands in the case before it, so this
run has no safe entry left and `apply.ts` answers `message:
'nothing_safe_to_apply'`. The expectation now states that exact value
(`toBe('nothing_safe_to_apply')`, was `toBeUndefined()`). No product
code changed.
- **Real-sqld runs on `715fc6a1`** (binary sha256 `28d1039e…816f`, `sqld
0.24.33 (40a151bd 2025-12-19)`, under the verify lock): driver-turso
`turso-remote-relax-not-null-sqld.test.ts` 2/2; cli
`apply.remote-face.integration.test.ts` 9/9. The red leg is the
measurement record itself (1 failed at :460 on both earlier heads).
## Fix round 4
Ruling-ref: 6922037129 (S1, letter A, the limit accepted). On the Turso
REMOTE face, a column whose stored definition holds a comma keeps its
NOT NULL. The apply lists it as not applied and says why, the docs name
the class, and no rebuild fall-back is added. Dev report 6922308957 on
#33724.
- **The reason, checked and then sharpened.** The not-applied listing
already existed: `os migrate apply` names the entry under "change(s)
were NOT applied — the driver could not perform them on this database
(its log above says why)", and `--json` carries it in `notApplied`. The
driver's warn line gave only the server's raw SQLite error. When the
refused definition holds a comma, the line now ends: `The column's
stored definition holds a comma, and libSQL's ALTER COLUMN ends the old
definition at the first comma after the column's name, so this transport
cannot relax it: the column keeps its NOT NULL`. Pinned on the comma
case; the comma-free unpredicted-splice case asserts the line does not
carry it.
- **Docs.** `content/docs/deployment/cli.mdx`, Turso remote paragraph,
names the class (a DEFAULT or CHECK with a comma, a type width such as
`NUMERIC(10, 2)`, a comment) and what the operator sees (listed not
applied, the log naming the comma, the column keeping `NOT NULL`, no
rebuild). Columns the platform creates on a remote primary are `TEXT`,
`INTEGER` or `REAL` with no DEFAULT and no width, so they are outside
the class.
- **Changeset.** Adds that a real `sqld` 0.24.33 refuses such a column
the same way, that the logged reason names the comma, and that the
maintainer accepted the limit.
- **Verification on `00fadc55`** (under the lock): full driver-turso
suite 2563 passed, 36 skipped; real `sqld` 0.24.33 pin 2/2. Ablation of
the comma-class condition reddens the comma case (1 failed, 17 passed);
restored to HEAD. Gates exit 0: check:doc-authoring, nul-bytes,
issue-citations, durability log level, changeset no-major / empty,
closing-keyword parity, docs section name.
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5pHNFS9mn8hS13iGyL -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 2d94860 commit 69949ae
12 files changed
Lines changed: 914 additions & 74 deletions
File tree
- .changeset
- content/docs/deployment
- packages
- cli/src/commands/migrate
- drivers/driver-turso/src
- runtime/src/domains
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1290 | 1290 | | |
1291 | 1291 | | |
1292 | 1292 | | |
1293 | | - | |
| 1293 | + | |
1294 | 1294 | | |
1295 | 1295 | | |
1296 | 1296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | | - | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
| |||
384 | 395 | | |
385 | 396 | | |
386 | 397 | | |
387 | | - | |
| 398 | + | |
388 | 399 | | |
389 | 400 | | |
390 | 401 | | |
| |||
396 | 407 | | |
397 | 408 | | |
398 | 409 | | |
399 | | - | |
| 410 | + | |
| 411 | + | |
400 | 412 | | |
401 | 413 | | |
402 | 414 | | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
406 | 418 | | |
407 | | - | |
| 419 | + | |
408 | 420 | | |
409 | 421 | | |
410 | 422 | | |
411 | 423 | | |
412 | 424 | | |
413 | | - | |
| 425 | + | |
414 | 426 | | |
415 | 427 | | |
416 | 428 | | |
| |||
419 | 431 | | |
420 | 432 | | |
421 | 433 | | |
422 | | - | |
| 434 | + | |
423 | 435 | | |
424 | 436 | | |
425 | 437 | | |
426 | 438 | | |
427 | 439 | | |
428 | | - | |
429 | | - | |
| 440 | + | |
| 441 | + | |
430 | 442 | | |
431 | 443 | | |
432 | 444 | | |
433 | 445 | | |
434 | 446 | | |
435 | | - | |
| 447 | + | |
436 | 448 | | |
437 | 449 | | |
438 | | - | |
| 450 | + | |
439 | 451 | | |
440 | 452 | | |
441 | 453 | | |
442 | 454 | | |
443 | 455 | | |
444 | 456 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
449 | 464 | | |
450 | 465 | | |
451 | | - | |
| 466 | + | |
452 | 467 | | |
453 | 468 | | |
454 | 469 | | |
455 | 470 | | |
456 | 471 | | |
457 | | - | |
| 472 | + | |
458 | 473 | | |
459 | 474 | | |
460 | 475 | | |
461 | 476 | | |
462 | 477 | | |
463 | 478 | | |
464 | | - | |
| 479 | + | |
465 | 480 | | |
466 | 481 | | |
467 | 482 | | |
| |||
473 | 488 | | |
474 | 489 | | |
475 | 490 | | |
476 | | - | |
| 491 | + | |
477 | 492 | | |
478 | 493 | | |
479 | 494 | | |
0 commit comments