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

Todo

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:databugdomain:datapm:dispatchedpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions