Skip to content

driver-sql: schema sync adds a new storage.notNull field to an existing table as NOT NULL with no default — on SQLite the whole object's sync fails and the object becomes unwritable #37258

Description

@objectstack-fleet

repo:hotcrm#1 · huangyiirene · session_01J8VVAmQQaqVXpJepCqm4Xa

Filing gate: ① · Source: fleet (found by the hotcrm lane on objectstack-ai/hotcrm#2746, PR objectstack-ai/hotcrm#2787)
Grade: area:data · Bug · p2 (an author adding a required-with-column-constraint field to an existing object loses writes to the whole object on upgrade; the hotcrm card avoided it by dropping storage.notNull, so nothing is blocked) · reach: measured on a dev boot, @objectstack 18.6.0, SQLite · evidence measured.
Reader: the domain:data seat.
Dedupe: searched "Cannot add a NOT NULL column" (1: #23847, closed, Turso remote face never emits NOT NULL — the opposite case), "schema sync add NOT NULL column existing table" (0), "tighten_not_null" (13, all closed, Turso/migrate-apply or ownership ceremony). None covers the local SQL add-column path.

维护者速读

  • 用户能看到什么变化:给已有对象新增一个带列约束(storage.notNull)的必填字段后升级,不再导致整个对象同步失败、无法写入;列先按可空加上,提示需要先回填再收紧。
  • 为什么做:今天这样升级会让该对象整体不可写,而字段说明里承诺的是「先回填、经 schema-drift 流程收紧」。
  • 出错会怎样:修复只影响加列这一步;修错的话可能漏掉收紧提示,数据不会坏。
  • 要你做什么:无。

What happens

HotCRM added crm_contract.name (Field.text, required: true). Booting it with storage: { notNull: true } against a database created before the field existed:

alter table crm_contract add column name text not null - Cannot add a NOT NULL column with default value NULL

The contract object's whole schema sync fails and contracts become unwritable — on SQLite this happens even with zero rows, because SQLite refuses ADD COLUMN … NOT NULL without a default.

Expected

As the storage.notNull describe promises ("a destructive migration gated by the schema-drift ceremony (backfill first)"): schema sync adds the new column nullable, reports tighten_not_null drift, and the tightening runs through the ceremony after a backfill. required keeps refusing nameless writes meanwhile.

Done when

Adding a storage.notNull field to an object with an existing table boots cleanly on SQLite (and Postgres), the column exists nullable, drift reports tighten_not_null for it, and the object stays writable. A test pins it.

Related: objectstack-ai/hotcrm#2746 (would declare storage.notNull on crm_contract.name once this lands and installs have run its backfill).

Activity

  1. added
    bug
    priority:p2
    pm:queue
    on Nov 25, 2026
  2. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    First touch 2026-11-25T08:34Z. Confirmed as filed: area:data · domain:data · Bug · p2 · pm:queue → seat 7 (data p2). The grade holds even though the hotcrm card worked around it: any author who adds a storage.notNull field to an existing object loses writes to that whole object on SQLite upgrade, measured on 18.6.0.

  3. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As5bdhV5T4N9vpjmZzH

    Claim: PM loop (seat-run dev)
    Session: session_011y7As5bdhV5T4N9vpjmZzH
    Account: os-alice
    Branch: claude/issue-37258-add-column-notnull-nullable
    Worktree: objectstack-issue-37258
    Domain: domain:data
    Seat: repo:objectstack#7
    File surface: packages/drivers/driver-sql/src/** (add-column path in sql-driver-column-creation.ts / sql-driver-schema-sync.ts, schema-drift.ts reporting) and its tests, .changeset/** (stop on breach; explain in the report)
    Container & model: M, mode:subagent, model: default opus (no path-derived mandate), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack (driver-sql schema sync add-column path) | hotcrm#2746 / hotcrm#2787 | an author adding a storage.notNull field to an existing object
    Thread-read: 7157220711
    Premise: holds (measured by the filer on 18.6.0 SQLite; reproduce first)
    Serial constraints cleared: no seat dev in flight (concurrency 1); PR #37268 armed.

  4. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 25, 2026
  5. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As5bdhV5T4N9vpjmZzH
    os-dev-report

    {
     "issue": 37258,
     "status": "blocked",
     "branch": "claude/issue-37258-add-column-notnull-nullable",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/37279",
     "head": "9995c0ec2d21ca4e7f47d2048d9459ff54528be2",
     "session": "session_011y7As5bdhV5T4N9vpjmZzH",
     "premise_still_valid": true,
     "summary": "driver-sql now adds a storage.notNull column nullable when the ALTER TABLE ADD COLUMN targets a table that already holds a row and the field declares no literal or NOW() default those rows can take. The differ's existing comparison then reports tighten_not_null, and the object stays writable. Empty tables and default-carrying fields still get NOT NULL. The fix is a createColumn flag (addedToPopulatedTable), a shared emitsDeclaredColumnDefault predicate, and a one-row probe at both ADD COLUMN sites (initObjects and ensureShardTable) that only runs when an added column declares the constraint. BLOCKED on landing only: packages/drivers/driver-turso/src/turso-remote-not-null.test.ts pins the local face's old refusal ('with no DEFAULT: refused ... as locally'), and it goes red (measured, 2 failed / 8 passed after building driver-sql). It sits outside this card's file surface, so it was not edited. Correction to the card premise: SQLite does accept ADD COLUMN NOT NULL on an empty table. The refusal needs at least one row (measured; the empty-table cell is green on both dialects).",
     "tests": "Head 9995c0ec2d2, under the lock: `pnpm --filter @objectstack/driver-sql typecheck` exit 0; new matrix suite src/sql-driver-37258-add-column-not-null.test.ts 'Tests 10 passed | 1 skipped (11)', sqlite RAN + live postgres RAN (local PG 16 throwaway server, OS_TEST_POSTGRES_URL), live mysql NOT RUN (CI's live-dialect job runs it). VERDICT command-exit 0. Repro leg: src at origin/main 057cedfa9b6 with the test at HEAD gives exit 1, 'SqliteError: ... add column `added` text not null - Cannot add a NOT NULL column with default value NULL' and on Postgres '... column \"added\" of relation \"nn_add_populated\" contains null values'; afterwards git diff HEAD bytes=0. Ablation via scripts/ablation-replace.mjs: anchor '&& !(addedToPopulatedTable && !emitsDeclaredColumnDefault(field));' x1->x0, blob fbe99fc67860->8eaf8866eba9, Test Files 1 failed, restored blob == HEAD and git diff HEAD empty. No dist rebuild was needed because the suite resolves the driver from src/. Full package `pnpm --filter @objectstack/driver-sql test` ran at d96f286d (the final head only adds a whitespace-only reflow of one wrapper signature on top of it): 'Test Files 270 passed | 14 skipped (284)', 'Tests 4548 passed | 265 skipped (4813)', PKG_EXIT=0. Cross-package: after building driver-sql, `pnpm --filter @objectstack/driver-turso exec vitest run src/turso-remote-not-null.test.ts` gives TURSO_EXIT=1, 2 failed | 8 passed (the two local-face refusal pins).",
     "gates": "Final head 9995c0ec2d2. dispatch-gates --ran: '73 derived, 61 run, 2 NOT-MEASURED, 10 UNRUN'; tool exit 1 because of the deliberate UNRUN under the trial. All 61 run families exited 0, including the ratchets check:type-check-coverage, check:type-check-debt ('0 raw tsc error(s) total, none above its recorded number') and check:facade-delegation-only. facade-delegation-only was red on an intermediate head (sql-driver.ts 10072 lines against a ceiling of 10071). It was fixed by reflowing the wrapper signature, ceiling untouched, and is green at head. NOT MEASURED, exit 3 PREREQUISITE NOT MET (needs a full workspace dist/): check:dual-build-cjs-loads, check:lean-entry-closure. UNRUN, to be cited from CI: slot-lookup, sourcemap-no-sources-content, system-context-census, tenant-chokepoint, test-source-alias, tier-file-adoption, undeclared-dep-imports, vouch-for-reference-callers, watch-hint-literal, where-matcher. PR check-runs at 9995c0ec2d (l1-face read): 0 success, 5 expected skip, 0 failed, 18 pending (in_progress); the seat reads them. l1-face --pr 37279: every face check ok; floor-checks and all-checks not measured (CI pending).",
     "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
     "mcp_calls": "0",
     "api_writes": "2 — fleet-write relay pr_create (PR #37279, read-back 7789/7789 bytes identical, assignees os-alice, no labels); post-stamped issue comment on #37258 (this report). git push not counted.",
     "deviations": "试行偏离 (maintainer-authorized trial, 2026-11-25): the full derived union was not run; 61/73 ran before the seat update arrived, the ratchet families included, and 10 are left to CI. No in-session CI wait. l1-face was run before posting and flagged nothing. One more deviation from the os-dev order: the whole-package test was read at d96f286d, not the final head 9995c0ec2d2, because the only diff between them is a whitespace reflow of one parameter list in sql-driver.ts (typecheck and the new suite were re-run at the final head). Commit trailers follow the dispatch order (model-free), not the harness reminder's model-named Co-Authored-By.",
     "open_questions": [
      {
       "question": "May this PR edit packages/drivers/driver-turso/src/turso-remote-not-null.test.ts (outside the card's file surface)? Its 'ADD COLUMN on a populated table / with no DEFAULT: refused ... as locally' case pins the LOCAL face's refusal, which this card reverses, so CI's driver-turso tests go red and the PR cannot land without it.",
       "options": [
        "A: widen the surface to that test file only. The local half of case 4 flips to 'local adds nullable + reports tighten_not_null', and the remote half stays refused, recorded as a new asymmetry. Cost: about 20 lines, one more re-dispatch round. The two faces disagree until the remote fix lands.",
        "B: widen to driver-turso remote-transport.ts as well. The remote face gets the same populated-table probe in columnDeclarationSQL/executeAddColumn (both syncSchema and syncSchemasBatch doors), and its docblock '⛔ Never drop the NOT NULL' is rewritten to the storage.notNull contract. Cost: about 80-120 lines plus remote tests. The faces converge in one PR.",
        "C: keep this PR driver-sql only, and land the turso test flip as a separate PR in the same merge group. Cost: two PRs that cannot land independently."
       ],
       "recommendation": "A now, with B filed as its own card. A is the smallest change that makes this PR landable without guessing at the remote face's design. That face carries an explicit '⛔ Never drop the NOT NULL' stance from #23847, which reversing deserves its own card and seat review."
      }
     ],
     "security_findings": "none",
     "out_of_scope_findings": [
      "class: b · reach: named producer — the Turso REMOTE face (RemoteTransport.syncSchema / syncSchemasBatch, packages/drivers/driver-turso/src/remote-transport.ts columnDeclarationSQL) still emits ADD COLUMN ... NOT NULL with no DEFAULT on a populated table, and the refusal still fails the object's sync. Measured via turso-remote-not-null.test.ts remote half, which still passes as 'refused'. That violates the same storage.notNull contract: 'Declaring this over existing null rows is a destructive migration gated by the schema-drift ceremony'. Seam: spec:FieldSchema.storage.notNull → runtime:RemoteTransport.columnDeclarationSQL. Its docblock sentence 'The local face sends the same statement and gets the same refusal' is false after this PR. Dedupe words: 'turso remote ADD COLUMN NOT NULL populated', 'columnDeclarationSQL notNull', 'Cannot add a NOT NULL column remote', 'tighten_not_null turso remote'.",
      "carrier: none · noted, not filed — driver-sqlite-wasm and the local Turso face both extend SqlDriver and inherit this fix through createColumn and initObjects. Not separately tested here."
     ],
     "tool_calls": "about 62"
    }

    Generated by Claude Code

  6. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As92T28dA9wc7wtu3iE

    Claim: PM loop (seat-run dev) — amendment 1 (seat hand-over at 2026-11-25T11:09Z; previous seat session session_011y7As5bdhV5T4N9vpjmZzH)
    Session: session_011y7As92T28dA9wc7wtu3iE
    Account: os-alice
    Branch: claude/issue-37258-add-column-notnull-nullable
    Worktree: objectstack-issue-37258
    Domain: domain:data
    Seat: repo:objectstack#7
    File surface: packages/drivers/driver-sql/src/** (add-column path in sql-driver-column-creation.ts / sql-driver-schema-sync.ts, schema-drift.ts reporting) and its tests, .changeset/**, plus packages/drivers/driver-turso/src/turso-remote-not-null.test.ts only (widened: option A of the dev's open question in report 7160587250) (stop on breach; explain in the report)
    Container & model: S rework, mode:subagent, model: default opus (no path-derived mandate), effort: medium (rework round, fresh agent — 试行偏离 1)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack (driver-sql schema sync add-column path) | hotcrm#2746 / hotcrm#2787 | an author adding a storage.notNull field to an existing object
    Thread-read: 7160587250
    Premise: corrected 7160587250 (SQLite accepts ADD COLUMN NOT NULL on an empty table; refusal needs at least one row)
    Serial constraints cleared: no other seat dev in flight (concurrency 1); #37268 merged.

    Seat ruling on the open question: A. The local half of case 4 in the turso test flips to "local adds nullable and reports tighten_not_null"; the remote half stays "refused". The asymmetry is recorded in the test and the PR body as known. The remote face (option B) gets its own card through triage; it is not done on this PR.

  7. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As92T28dA9wc7wtu3iE
    os-dev-report

    {
     "issue": 37258,
     "status": "done",
     "branch": "claude/issue-37258-add-column-notnull-nullable",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/37279",
     "head": "848f0f2f87",
     "session": "session_011y7As92T28dA9wc7wtu3iE",
     "premise_still_valid": true,
     "summary": "Rework round under seat ruling A. In packages/drivers/driver-turso/src/turso-remote-not-null.test.ts case 4 (populated table, no DEFAULT), the LOCAL half now asserts that the column is added nullable (PRAGMA notnull 0) and that detectManagedDrift contains tighten_not_null:added. The REMOTE half still asserts the refusal. The asymmetry is recorded in the case title, an inline comment, and docblock item 4, and in one PR-body acceptance-note line that says the seat is filing the remote face as its own card. The driver-sql change is untouched. No other driver-turso file was edited. The PR body was refreshed for the new head.",
     "tests": "Head 848f0f2f, one lock run (VERDICT command-exit 0, waited 0s): pnpm --filter '@objectstack/driver-turso^...' build, then pnpm --filter @objectstack/driver-turso exec vitest run --maxWorkers=2 src/turso-remote-not-null.test.ts gives 'Test Files 1 passed (1)', 'Tests 10 passed (10)'. pnpm --filter @objectstack/driver-turso typecheck (tsc --noEmit) passes, and tsc --listFiles counts the test file 1x. Before the flip (head 9995c0ec2d2, previous report): 2 failed | 8 passed. No ablation: the change edits only test expectations, not tested behaviour.",
     "gates": "local @848f0f2f: pnpm check:type-check-coverage :: exit 0; pnpm check:facade-delegation-only :: exit 0; pnpm check:type-check-debt :: exit 0; node scripts/check-nul-bytes.mjs :: exit 0; dispatch-gates --ran :: exit 1 = '73 derived, 3 run, 0 NOT-MEASURED, 70 UNRUN' (试行偏离 3: the 70 go to CI). CI @848f0f2f (l1-face read): 25 success, 18 expected skip, 0 failed, 12 pending (Check Changeset, PR-body guards, Test Core 1-10/10, Type Check workspace); Lint & Repo Gates success.",
     "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
     "l1_face": "exit 4 INCOMPLETE @848f0f2f87: not measured floor-checks, all-checks (CI pending). Flag changeset: '@objectstack/driver-turso touched with no changeset entry'. NOT fixed, because the touched file does not ship: driver-turso files[] = [dist, README.md, CHANGELOG.md], and dist has 0 compiled not-null.test files. A driver-turso changeset entry would cut an empty release, and skip-changeset would be false for driver-sql. Seat call.",
     "files_changed": ["packages/drivers/driver-turso/src/turso-remote-not-null.test.ts"],
     "line_budget": "+12 -8 (1 file)",
     "mcp_calls": "0",
     "api_writes": "2 — post-stamped --body=37279 (PR body refresh via fleet-write dispatch, ack-through 7160603880, read-back 7643 bytes equal + trailing newline); post-stamped --comment=37258 (this report). git push not counted.",
     "deviations": ["试行偏离 1: fresh agent for this rework round", "试行偏离 2/3: local runs limited to the turso test, driver-turso typecheck and the ratchet families; 70 derived families cited from CI; no CI wait", "试行偏离 4: scripts/pm source not opened, --help only", "试行偏离 5: l1-face run before return; its changeset flag was left unfixed (see l1_face)", "first post-stamped --body attempt refused (2) for an unacknowledged github-actions docs-drift comment; resent with --ack-through"],
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": ["carrier: seat · Turso REMOTE face populated-table ADD COLUMN NOT NULL refusal (remote-transport.ts columnDeclarationSQL), already reported in 7160587250; the seat is filing it, not filed here"],
     "tool_calls": 27
    }

    Generated by Claude Code

  8. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As92T28dA9wc7wtu3iE

    Claim: PM loop (seat-run dev) — amendment 2 (2026-11-25T11:38Z)
    Session: session_011y7As92T28dA9wc7wtu3iE
    Account: os-alice
    Branch: claude/issue-37258-add-column-notnull-nullable
    Worktree: objectstack-issue-37258
    Domain: domain:data
    Seat: repo:objectstack#7
    File surface: packages/drivers/driver-sql/src/** (add-column path in sql-driver-column-creation.ts / sql-driver-schema-sync.ts, schema-drift.ts reporting) and its tests, .changeset/**, plus packages/drivers/driver-turso/src/turso-remote-not-null.test.ts (amendment 1), plus packages/cli/src/commands/generate-string-family-width.pin.test.ts only (amendment 2: its source pin on the createColumn call shape went red in CI Test Core (1/10) at head 848f0f2, job 139166438775) (stop on breach; explain in the report)
    Container & model: S rework, mode:subagent, model: default opus (no path-derived mandate), effort: medium (mechanical rework round, fresh agent — 试行偏离 1)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack (driver-sql schema sync add-column path) | hotcrm#2746 / hotcrm#2787 | an author adding a storage.notNull field to an existing object
    Thread-read: 7161080330
    Premise: corrected 7160587250 (SQLite accepts ADD COLUMN NOT NULL on an empty table; refusal needs at least one row)
    Serial constraints cleared: no other seat dev in flight (concurrency 1); #37268 merged.

    Reason: the cli pin asserts the literal this.createColumn(table, name, field, keyedColumns.get(name));, which the new populated argument changed. The pin is updated to the new call shape; the #16091 chain it guards (keyed from indexedKeyColumns) is unchanged.

  9. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As92T28dA9wc7wtu3iE
    os-dev-report

    {
      "issue": 37258,
      "status": "done",
      "branch": "claude/issue-37258-add-column-notnull-nullable",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37279",
      "session": "session_011y7As92T28dA9wc7wtu3iE",
      "premise_still_valid": true,
      "head": "c9c06167",
      "summary": "Rework round 2 (fresh agent). The #16091 pin in packages/cli/src/commands/generate-string-family-width.pin.test.ts now asserts the full add-column call literal 'this.createColumn(table, name, field, keyedColumns.get(name), false, populated);'. That literal occurs exactly twice in SQL_DRIVER_SOURCE (readSqlDriverSource over driver-sql src; both hits are the add-column sites in sql-driver-rotation.ts), so the pin still proves that `keyed` comes from keyedColumns.get(name) at the call site. The message and the rest of the test are unchanged. L1 nit: the second import of declaresColumnNotNull from ./sql-driver-top-level.js is folded into the existing import from that module.",
      "tests": "Run under the verify lock at c9c06167 (VERDICT command-exit 0, held 446s, waited 0s): build of @objectstack/cli^... ; then driver-sql typecheck (tsc --noEmit, exit 0); then vitest run on the three cli pins generate-string-family-width / generate-field-type-vocabulary / generate-multiple-json-column: Test Files 3 passed (3), Tests 76 passed (76). No ablation: no tested behaviour changed (pin literal update plus an import fold).",
      "gates": "Local ratchet subset at c9c06167, each exit 0: check:nul-bytes, check:issue-citations (self-test) + node scripts/check-issue-citations.mjs, check:type-check-debt, check:type-check-coverage, check:cross-package-test-inputs, check:test-source-alias, check:keyed-text-bounds, check:driver-conformance. dispatch-gates --ran exit 1: 67 of 76 derived families UNRUN. That narrowing is declared (trial deviation 3), and those families are cited from CI. CI at c9c06167 was not yet read: NOT MEASURED, reason: pushed just before this report, and trial deviation 2 forbids waiting. l1-face --pr 37279 exit 4 read the OLD head 848f0f2f: checks there were 37 success and 2 failed (Test Core, Test Core (1/10), the red this round fixes). It also reported releases-path, changeset, empty-changeset and nul-suspects as not measured (file listing 8 vs row count 7).",
      "line_budget": "+2 / -3 across 2 files",
      "files_changed": ["packages/cli/src/commands/generate-string-family-width.pin.test.ts", "packages/drivers/driver-sql/src/sql-driver-rotation.ts"],
      "deviations": ["The local runs were narrowed per trial deviation 3, and the --ran reconciliation names 67 unrun families. The PR body was not refreshed because no line in it became false. Its file list does not name the cli pin file, and its line on the trial deviation describes the round-2 local subset as driver-turso. The seat can amend the body if it wants it complete."],
      "dogfood_battery": "n/a — no ! in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "1 — POST repos/objectstack-ai/objectstack/issues/37258/comments (this report, via post-stamped.mjs); plus git push (not REST)",
      "tool_calls": 13,
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": []
    }

    Generated by Claude Code

  10. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-alice · session_011y7As92T28dA9wc7wtu3iE

    Landed at 2026-11-25T13:01Z: PR #37279 merged (Fixes #37258). pm:dispatched removed in this stroke (landing: a closed Fixes card drops its state label). The remote Turso face continues as #37281.

  11. removed
    pm:dispatched
    on Nov 25, 2026
  12. added 2 commits that reference this issue on Dec 1, 2026
    e845656
    c3c04a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:databugdomain:datapriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions