Skip to content

Commit 69949ae

Browse files
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/driver-turso': patch
3+
---
4+
5+
fix(driver-turso): Turso's remote face relaxes a NOT NULL column in place, so a package upgrade that makes a field optional reaches hosted databases
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
On Turso's remote face (`libsql://`, every hosted tenant database), a `relax_not_null` drift entry is now applied. Until now it was skipped with "it needs the SQLite table rebuild, which the Turso REMOTE transport does not run". A package upgrade that declares `storage: { notNull: false }` on a column therefore left the column NOT NULL on a hosted database, and every save that left the field empty failed.
11+
12+
The maintainer ruled how (decision record 6915086281 on #33724): the column is relaxed in place with libSQL's own column statement, `ALTER TABLE t ALTER COLUMN c TO c <definition>`, and no table rebuild runs.
13+
14+
- **Only the NOT NULL clause changes.** The definition sent is the column's own, cut from the table's stored `CREATE TABLE` with only its `[CONSTRAINT name] NOT NULL [ON CONFLICT …]` clause removed. The type, the DEFAULT, and any CHECK, COLLATE, UNIQUE or REFERENCES clause stay byte for byte. No row is copied or revalidated.
15+
- **Applied only on a read-back.** The statement is sent in one `write` batch with a check that the table's stored SQL now reads exactly as planned. If it reads any other way, the batch rolls back. The entry is reported `applied` only when the column then reads back nullable, with the type, the DEFAULT and the primary-key position it had before.
16+
- **A refusal is reported, and nothing falls back.** A statement the database refuses, a stored definition the plan cannot read, or a read-back that differs is reported `skipped`, and the reason is logged. Measured on libSQL (SQLite 3.45.1): libSQL ends the old definition at the first comma after the column's name, so a column whose definition holds a comma (in a DEFAULT, a CHECK, a type width such as `NUMERIC(10, 2)`, or a comment) is refused that way, and a real `sqld` 0.24.33 refuses it the same way. It keeps its NOT NULL, the table is left byte-identical, and the logged reason says the definition holds a comma. The maintainer accepted this limit (decision record 6922037129 on #33724): no table rebuild is added for such a column. Columns this face creates are `TEXT`, `INTEGER` or `REAL` with no DEFAULT and no width, so they are never in it.
17+
18+
The same three acts reach the relax as before: a managed install or upgrade of a package that declares `storage: { notNull: false }` on the column, the publish of an environment-authored object, and `os migrate apply`. A boot still never alters a column (ADR-0113 D5). 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. So `os migrate plan` and the apply's listing show a relax on a remote database with no transport limit, and count one fewer change they cannot apply.
19+
20+
A tightened NOT NULL, a dropped DEFAULT, and the type and width entries keep their answer on this face: skipped, because they need the table rebuild. The statement does not revalidate existing rows, so it is never used to tighten. A local SQLite file keeps the existing table rebuild for every column entry.

‎content/docs/deployment/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ field declares `storage: { notNull: false }`, since that declaration is the deli
12901290
changes stay with `os migrate apply`. A column change the database could not apply leaves the publish
12911291
a success with an `object-column-changes-not-applied` warning on its answer naming each column.
12921292
1293-
On a Turso remote primary (`libsql://`), a tightened or relaxed `NOT NULL` and a dropped DEFAULT stay drift, because that transport runs no SQLite table rebuild. `os migrate plan` and `os migrate apply` list each such entry with `"os migrate apply" cannot apply it on this database: it needs the SQLite table rebuild, which the Turso REMOTE transport does not run.`, offer `--allow-destructive` only for the destructive changes that database can apply, and count the rest as drift a re-run cannot apply.
1293+
On a Turso remote primary (`libsql://`), a relaxed `NOT NULL` is applied in place, with libSQL's own `ALTER TABLE … ALTER COLUMN … TO …`: only the `NOT NULL` clause leaves the column's stored definition, no row is copied, and the entry counts as applied only once the column reads back nullable with the type and DEFAULT it had. A database that refuses that statement leaves the column as it was, and the entry is listed as not applied. libSQL refuses it for a column whose stored definition holds a comma: a DEFAULT or a CHECK with a comma in it, a type width such as `NUMERIC(10, 2)`, or a comment. Such a column keeps its `NOT NULL` and the table is left as it was; `os migrate apply` lists the entry as not applied, its log says the definition holds a comma, and no table rebuild is attempted. Columns the platform creates on a remote primary are `TEXT`, `INTEGER` or `REAL` with no DEFAULT and no width, so they never hold a comma. A tightened `NOT NULL` and a dropped DEFAULT stay drift there, because that transport runs no SQLite table rebuild. `os migrate plan` and `os migrate apply` list each such entry with `"os migrate apply" cannot apply it on this database: it needs the SQLite table rebuild, which the Turso REMOTE transport does not run.`, offer `--allow-destructive` only for the destructive changes that database can apply, and count the rest as drift a re-run cannot apply.
12941294
12951295
`--allow-destructive` refuses some drops until the data they would lose is
12961296
safe. No flag skips these refusals:

‎packages/cli/src/commands/migrate/apply.remote-face.integration.test.ts‎

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
* - `code`, nullable, under a field declaring `storage: { notNull: true }`: a
2727
* `tighten_not_null` (destructive), which needs the SQLite table rebuild;
2828
* - `memo`, NOT NULL, under a field declaring no constraint: a
29-
* `relax_not_null` (needs confirm), which needs the rebuild too.
29+
* `relax_not_null` (needs confirm), which the remote face applies in place
30+
* with libSQL's `ALTER TABLE … ALTER COLUMN … TO …` [#33724, ruling
31+
* 6915086281], so the first apply that confirms it relaxes the column and
32+
* the cases after it no longer find it.
3033
*
3134
* The table is made by hand so the drift does not depend on what the remote
3235
* schema sync creates. Then the environment's own syncing boot, then the real
3336
* commands, and every claim about the server is read back through a SECOND
3437
* libSQL connection.
3538
*
3639
* [#23925] The human plan says the same thing up front, read from the driver's
37-
* declaration (`TursoDriver.driftApplyLimit`): the tightening and the relax
38-
* are listed with the transport's limit instead of a remedy it cannot run, and
40+
* declaration (`TursoDriver.driftApplyLimit`): the tightening is listed with
41+
* the transport's limit instead of a remedy it cannot run (the relax, which the
42+
* transport applies, with none [#33724]), and
3943
* the drop keeps `--allow-destructive`. So does the apply's own listing before
4044
* its prompt, whose held-back count offers a re-run only for the drop. The
4145
* local file is the control: its plan and its apply read as they always have.
@@ -72,6 +76,13 @@ import MigratePlan from './plan.js';
7276
// Paid at module load, not inside a clocked case (`check:test-source-alias`).
7377
import '@objectstack/runtime';
7478
import '@objectstack/objectql';
79+
import '@objectstack/service-datasource';
80+
import '@objectstack/driver-sql';
81+
import '@objectstack/metadata-protocol';
82+
import '@objectstack/platform-objects/plugin';
83+
import '@objectstack/platform-objects/system';
84+
import '@objectstack/plugin-security';
85+
import '@objectstack/rest';
7586

7687
const SQLD = process.env.OS_TEST_SQLD_BIN;
7788
const HERE = dirname(fileURLToPath(import.meta.url));
@@ -384,7 +395,7 @@ describe.skipIf(!SQLD)('os migrate plan / apply on a Turso REMOTE database (sqld
384395

385396
// [#23925] Before the apply below names them as not applied, the plan says so:
386397
// read from the driver's declaration, never from the dialect or the URL.
387-
it('plan, human face: the tightening and the relax name the transport\'s limit, never --allow-destructive; the drop keeps it', async () => {
398+
it('plan, human face: the tightening names the transport\'s limit, never --allow-destructive; the relax names none; the drop keeps it', async () => {
388399
const before = await logicalDump();
389400
const plan = await run(MigratePlan, ['--database-url', url]);
390401
expect(plan.exitCode, plan.lines.slice(-1500)).toBe(0);
@@ -396,21 +407,22 @@ describe.skipIf(!SQLD)('os migrate plan / apply on a Turso REMOTE database (sqld
396407
+ '"os migrate apply" cannot apply it on this database: it needs the SQLite table rebuild, which the Turso REMOTE '
397408
+ 'transport does not run.',
398409
);
399-
expect(planEntryLine(plan.lines, 'relax_not_null')).toContain('"os migrate apply" cannot apply it on this database');
410+
// [#33724] Applied in place on this transport: no limit beside it.
411+
expect(planEntryLine(plan.lines, 'relax_not_null')).not.toContain('cannot apply it on this database');
400412
const drop = planEntryLine(plan.lines, 'drop_column');
401413
expect(drop).toContain('"os migrate apply --allow-destructive" to drop it.');
402414
expect(drop).not.toContain('cannot apply it on this database');
403415

404416
const footer = planFooter(plan.lines);
405417
expect(footer).not.toContain('drops / tightenings');
406418
expect(footer).toContain('Apply with: os migrate apply (add --allow-destructive for the 1 destructive change(s) it can apply on this database)');
407-
expect(footer).toMatch(/2 change\(s\) above cannot be applied on this database by "os migrate apply"/);
419+
expect(footer).toMatch(/1 change\(s\) above cannot be applied on this database by "os migrate apply"/);
408420
expect(await logicalDump()).toBe(before);
409421
}, CASE_TIMEOUT_MS);
410422

411423
// [#23925] The apply's own listing says the same before its prompt, and offers
412424
// a re-run with --allow-destructive only for the drop that re-run could apply.
413-
it('apply --yes, human face: the listing names the limit, and only the drop is offered a re-run', async () => {
425+
it('apply --yes, human face: the listing names the limit, only the drop is offered a re-run, and the confirmed relax lands', async () => {
414426
const apply = await run(MigrateApply, ['--database-url', url, '--yes']);
415427
expect(apply.exitCode, apply.lines.slice(-1500)).toBe(0);
416428
const tighten = planEntryLine(apply.lines, 'tighten_not_null');
@@ -419,49 +431,52 @@ describe.skipIf(!SQLD)('os migrate plan / apply on a Turso REMOTE database (sqld
419431
'"os migrate apply" cannot apply it on this database: it needs the SQLite table rebuild, which the Turso REMOTE '
420432
+ 'transport does not run.',
421433
);
422-
expect(planEntryLine(apply.lines, 'relax_not_null')).toContain('"os migrate apply" cannot apply it on this database');
434+
expect(planEntryLine(apply.lines, 'relax_not_null')).not.toContain('cannot apply it on this database');
423435
expect(planEntryLine(apply.lines, 'drop_column')).toContain('"os migrate apply --allow-destructive" to drop it.');
424436
expect(heldBackLines(apply.lines)).toEqual([
425437
' ⚠ 1 destructive change(s) will be SKIPPED (re-run with --allow-destructive to include them).',
426438
' ⚠ 1 destructive change(s) remain drift that a re-run with --allow-destructive cannot apply on this database either (each says why above).',
427439
]);
428-
// Unchanged after the prompt: the relax the driver could not apply is still named.
429-
expect(apply.lines).toContain(`${TABLE}.memo — relax_not_null`);
440+
// [#33724] After the prompt: the relax was applied, so it is not named among what was not.
441+
expect(apply.lines).not.toContain(`${TABLE}.memo — relax_not_null`);
430442
// The post-apply held-back line splits the same way.
431443
expect(postApplySkippedLines(apply.lines)).toEqual([
432444
' ⚠ Skipped 1 destructive change(s) (re-run with --allow-destructive to include them).',
433445
' ⚠ Skipped 1 destructive change(s) that a re-run could not apply on this database either: they remain drift (each says why above).',
434446
]);
435-
expect(await remote(columnsOf)).toMatchObject({ code: false, memo: true, legacy_23848: false });
447+
expect(await remote(columnsOf)).toMatchObject({ code: false, memo: false, legacy_23848: false });
436448
}, CASE_TIMEOUT_MS);
437449

438-
it('apply without --allow-destructive: names the entry it could not apply, keeps the destructive two back, exits 0', async () => {
450+
it('apply without --allow-destructive: nothing left it cannot apply, keeps the destructive two back, exits 0', async () => {
439451
const apply = await run(MigrateApply, ['--database-url', url, '--yes', '--json']);
440452
expect(apply.payload.error, JSON.stringify(apply.payload).slice(0, 800)).toBeUndefined();
441453
expect(apply.exitCode).toBe(0);
442454
expect(apply.payload.schemaSync).toBe('skipped');
443455
expect(apply.payload.created).toEqual([]);
444456
expect(kinds(apply.payload.applied)).toEqual([]);
445-
expect(kinds(apply.payload.notApplied)).toEqual([RELAX]);
446-
expect(kinds(apply.payload.skipped)).toEqual([DROP, TIGHTEN, RELAX].sort());
447-
expect(apply.payload.message).toBeUndefined();
448-
expect(await remote(columnsOf)).toMatchObject({ code: false, memo: true, legacy_23848: false });
457+
// [#33724] The relax landed in the case before: it is drift no more.
458+
expect(kinds(apply.payload.notApplied)).toEqual([]);
459+
expect(kinds(apply.payload.skipped)).toEqual([DROP, TIGHTEN].sort());
460+
// With the relax applied, nothing is left that this run may apply, and the
461+
// apply says so (measured on sqld 0.24.33, record 6921391723).
462+
expect(apply.payload.message).toBe('nothing_safe_to_apply');
463+
expect(await remote(columnsOf)).toMatchObject({ code: false, memo: false, legacy_23848: false });
449464
}, CASE_TIMEOUT_MS);
450465

451-
it('apply --allow-destructive: the drop lands on the server, the two it cannot express are named, the verdict is partial', async () => {
466+
it('apply --allow-destructive: the drop lands on the server, the tightening it cannot express is named, the verdict is partial', async () => {
452467
const apply = await run(MigrateApply, ['--database-url', url, '--allow-destructive', '--yes', '--json']);
453468
expect(apply.payload.error, JSON.stringify(apply.payload).slice(0, 800)).toBeUndefined();
454469
expect(apply.exitCode).toBe(1);
455470
expect(apply.payload.message).toBe('partial');
456471
expect(kinds(apply.payload.applied)).toEqual([DROP]);
457-
expect(kinds(apply.payload.notApplied)).toEqual([TIGHTEN, RELAX].sort());
472+
expect(kinds(apply.payload.notApplied)).toEqual([TIGHTEN]);
458473

459474
const after = await remote(async (exec) => ({
460475
columns: await columnsOf(exec),
461476
rows: (await exec(`SELECT id, code, memo FROM "${TABLE}" ORDER BY id`)).map((r) => ({ ...r })),
462477
}));
463478
expect(after.columns).not.toHaveProperty('legacy_23848');
464-
expect(after.columns).toMatchObject({ code: false, memo: true });
479+
expect(after.columns).toMatchObject({ code: false, memo: false });
465480
expect(after.rows).toEqual([{ id: 'n1', code: 'c1', memo: 'm1' }]);
466481
}, CASE_TIMEOUT_MS);
467482

@@ -473,7 +488,7 @@ describe.skipIf(!SQLD)('os migrate plan / apply on a Turso REMOTE database (sqld
473488
expect(planEntryLine(apply.lines, 'tighten_not_null')).toContain('"os migrate apply" cannot apply it on this database');
474489
expect(planEntryLine(apply.lines, 'tighten_not_null')).not.toContain('--allow-destructive');
475490
expect(apply.lines).toContain(`${TABLE}.code — tighten_not_null`);
476-
expect(apply.lines).toContain(`${TABLE}.memo — relax_not_null`);
491+
expect(apply.lines).not.toContain(`${TABLE}.memo — relax_not_null`);
477492
expect(apply.lines).toMatch(/PARTIAL/);
478493
}, CASE_TIMEOUT_MS);
479494
});

0 commit comments

Comments
 (0)