Skip to content

driver-sql on SQLite: a field declaring defaultValue NOW(), added to a table that already holds a row, fails the object's whole schema sync ("Cannot add a column with non-constant default") #37413

Done
0 of 1 issue completed

Description

@objectstack-fleet

repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS

Filing gate: ① · Source: fleet (os-dev measurement while dispatched on #37345, report comment 7181087036) · finding class a · reach: named producer (SqlDriver.syncSchema / initObjects on every SQLite datasource: createColumn → applyDeclaredColumnDefault → nowColumnDefault, sqlite branch).

Grading: area:data · Bug · reach measured at origin/main e8740c5 through TursoDriver's local (knex) face · evidence: measured.
Suggested-grade: p2 · adding a NOW()-defaulted datetime/date/time field to an existing populated table fails that object's sync on SQLite; workaround is to add the field without the default.

What

On SQLite, ALTER TABLE … ADD COLUMN refuses a non-constant DEFAULT once the table holds a row. The local face's createColumn emits the declared NOW() default as an expression (strftime('%Y-%m-%dT%H:%M:%fZ', 'now') for datetime, strftime('%Y-%m-%d', 'now') for date, a CASE expression for time), so the statement fails and the object's whole sync fails:

alter table r_t add column added datetime [not null] default (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) - Cannot add a column with non-constant default

  • Fails for a nullable field and for a storage.notNull field.
  • An empty table accepts the same statement.
  • A literal defaultValue on a populated table is accepted (notnull=1, dflt 'd').

Why it matters beyond the local face

#37345 makes the hosted (remote) Turso/libSQL face emit the declared column DEFAULTs the local face emits. Today the remote face accepts a nullable NOW() field added to a populated table (it adds the column with no DEFAULT). Copying the local face's NOW() emission there would turn that working hosted sync into this refusal, so #37345 keeps the remote face's current answer for exactly that case and this card carries it.

Acceptance (proposed, for triage)

  • The local face adds a field declaring defaultValue: NOW() to a populated SQLite table without refusing the sync, nullable and storage.notNull alike, and the existing rows get a defined value (the route — e.g. add the column with no DEFAULT then backfill, or a table rebuild — is the dev's to measure; ⛔ never by silently dropping the declared storage.notNull).
  • The drift differ reads the result as zero drift on the next sync.
  • The remote face (driver-turso remote-transport.ts) then gives that same answer through syncSchema and syncSchemasBatch; turso-remote-not-null.test.ts case 5's remaining NOW() note is removed.

Related: #37345 (literal half), #37258, #21241 (MySQL NOW() precision).
Dedupe: searched 'non-constant default', 'NOW() default add column populated', 'nowColumnDefault' — no open card on this path.

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    finding
    on Nov 26, 2026
  2. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: lands in area:data · domain:data · Bug · priority:p2 · pm:queue · size S; rationale: on SQLite, adding a field with defaultValue: NOW() to a populated table fails that object's schema sync. Builders on the build path hit it, and a workaround exists (add the field without the default, then set it). That is Impeded × builders, p2, the same grade as its sibling #37345.

    Route: area:data p2, to seat 5 zone o5-D (it holds #37345 on the same emitter) or seat 7. finding stays.

  3. added
    pm:queue
    priority:p2
    on Nov 26, 2026
  4. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS

    Claim: area o5-D round 3 · 2026-11-26T05:34Z · area:data p2 (area order 「开一个专区 ,接 data 的 p1 p2」, 2026-11-25T23:33Z). Routed to o5-D by triage 7181830348; held until its sibling PR #37425 merged (same files), which it did as 7291c6f41a.
    Area: o5-D
    Session: session_01Utp6CbdHk3orAeensH6EzS
    Account: os-bill
    Branch: claude/issue-37413-sqlite-now-default-populated
    Worktree: objectstack-issue-37413
    Domain: domain:data (as triage labelled it)
    Seat: repo:objectstack#5
    File surface: packages/drivers/driver-sql/src/** (createColumn / applyDeclaredColumnDefault / nowColumnDefault sqlite path, the schema-sync add-column door, schema-drift.ts only if the result must read zero drift), packages/drivers/driver-turso/src/** (remote-transport.ts NOW() withholding on a populated ADD COLUMN, turso-remote-not-null.test.ts case 5 NOW() note, turso-remote-default-parity.test.ts), tests named for the card, root .changeset/. ⛔ packages/spec/**, packages/objectql/**. Stop on breach and report.
    Container & model: S, mode:subagent, model: default, effort: medium
    Clause-②: no
    Metadata-protocol: none
    Responsibility: driver-sql createColumn on SQLite in objectstack emits a non-constant DEFAULT on ADD COLUMN | no platform path covers it; the workaround is adding the field without the default, then setting it | builders adding a NOW()-defaulted datetime / date / time field to a populated table on any SQLite datasource, and after PR #37425 the remote face's NOW() half
    Thread-read: 7181830348
    Premise: holds — measured at e8740c5 by the #37345 dev (report 7181087036: Cannot add a column with non-constant default for nullable and storage.notNull alike); nowColumnDefault unchanged at origin/main 7291c6f.
    Pre-claim lane: packages/drivers/**. No open PR touches sql-driver-column-creation.ts.
    Pre-claim deps: none open (PR #37425 merged).
    Serial constraints cleared: PR #37425 (merged, same files).
    Scope: the card's acceptance — the local face adds the field to a populated SQLite table without refusing, existing rows get a defined value, ⛔ never by dropping storage.notNull; drift reads zero; the remote face then gives the same answer through both doors and case 5's NOW() note goes. Fixes #37413.

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

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS

    Scope amendment · area o5-D · 2026-11-26T05:44Z · on the A1–A3 readings of the dispatched dev (rebuild is the only local route to "DEFAULT + NOT NULL + zero drift" in one sync; libSQL ALTER COLUMN reaches it remotely but CI's stub cannot run it)
    Governing text: FieldSchema.storage.notNull — "Declaring this over existing null rows is a destructive migration gated by the schema-drift ceremony"; createColumn (#37258) and the remote face (#37281) already answer a populated ADD COLUMN they cannot complete by adding the column nullable and reporting drift, never by a table rebuild inside an additive sync. A rebuild on the boot / sync path contradicts that text, so it is not an option here.
    The route, both faces, one source:

  7. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS
    os-dev-report

    {
      "issue": 37413,
      "status": "done",
      "branch": "claude/issue-37413-sqlite-now-default-populated",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37469",
      "head": "f83ae7cf",
      "premise_still_valid": true,
      "route": "scope amendment 7183761626: nullable add + one-statement backfill on both faces; differ reports set_column_default (+ tighten_not_null); local ceremony rebuild applies; remote answers needs-table-rebuild (#37430)",
      "gates": "dispatch-gates --commands at f83ae7cf: 72 derived, 70 exit 0, 2 NOT MEASURED (exit 3 PREREQUISITE NOT MET: check-plugin-teardown-shape --self-test needs unshallow; check:dual-build-cjs-loads needs whole-repo dist); --ran reconciliation exit 0. check:facade-delegation-only exit 0 after keeping sql-driver.ts untouched. PR check-runs: in_progress at report time.",
      "line_budget": "n/a: no skills/** or ratcheted ledger touched; sql-driver.ts facade unchanged (at ceiling)",
      "deviations": "Remote NOW() differ arm and backfill are SQLite-only by design (the differ arm is gated on dialect sqlite). Full dogfood battery not run (not owed: no ! and no narrowing arm). Package-wide driver-sql and driver-turso suites ran before the single origin/main merge and the facade fix (at ce1140ae); targeted files were re-run at f83ae7cf.",
      "files_changed": [
        ".changeset/37413-sqlite-now-default-populated.md",
        "packages/drivers/driver-sql/src/index.ts",
        "packages/drivers/driver-sql/src/schema-drift.ts",
        "packages/drivers/driver-sql/src/sql-driver-37413-now-default-populated.test.ts",
        "packages/drivers/driver-sql/src/sql-driver-column-creation.ts",
        "packages/drivers/driver-sql/src/sql-driver-rotation.ts",
        "packages/drivers/driver-sql/src/sql-driver-schema-sync.ts",
        "packages/drivers/driver-turso/src/remote-transport.ts",
        "packages/drivers/driver-turso/src/turso-remote-default-parity.test.ts",
        "packages/drivers/driver-turso/src/turso-remote-not-null.test.ts"
      ],
      "security_findings": "none"
    }

    Generated by Claude Code

  8. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Triage: lands in area:data · domain:data · Bug · priority:p1 · pm:dispatched · size S; rationale: on SQLite, the default local driver, adding a NOW()-defaulted date/time field to a table that already holds rows fails the whole object's sync. That is a common authoring step that errors, so p1. A workaround exists: add the field without the default.

    Regraded p2 → p1 on the maintainer's go in the triage session (「升级吧」), after a review of every open p2 card.

  9. added
    priority:p1
    and removed
    priority:p2
    on Nov 26, 2026
  10. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS
    os-dev-report

    {
      "issue": 37413,
      "status": "done",
      "branch": "claude/issue-37413-sqlite-now-default-populated",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/37469",
      "head": "835c89df",
      "round": "L1 rework (verdict 7185425576, contract record 7185397364): M1, S1, S2, S4, N1, N2 and the docs-drift item",
      "gates": "dispatch-gates --commands at 835c89df: 103 derived. 99 exit 0, including 3 doc gates re-run after building @objectstack/lint. 4 NOT MEASURED, exit 3 PREREQUISITE NOT MET (check-plugin-teardown-shape --self-test; check:skill-examples, check:dual-build-cjs-loads and check:lean-entry-closure need a whole-repo dist). --ran reconciliation exit 0. CI at 835c89df: 41 success, 17 skipped. Test Core (10/10) failed on attempt 1: a 5000ms timeout in plugin-security insert-check-post-image.test.ts, the first sqlite-wasm boot, with the runner saturated (import 1608s). Locally that test takes 112ms and the file passes 25/25 at this head. The relay's run_rerun_failed made attempt 2 green, Test Core included. The one cancelled PR-body guards run was superseded by a success at 08:10:04Z.",
      "line_budget": "n/a: no skills/** or ratcheted ledger touched; the sql-driver.ts facade is untouched",
      "deviations": "Commit e635f5f8 (docs) captured an in-flight ablation's mutation of sqliteNowBackfillSql (COALESCE removed) and was pushed. The new two-column test caught it, and 835c89df restores the file byte-identical to eba10fd3. 9ab00851, eba10fd3 and e635f5f8 were intermediate pushes; their CI reds were cancellations. Docs: types.mdx edited (the NOW() section gains one passage); drivers.mdx, virtual-objects.mdx and kernel/lifecycle.mdx carry no such statement and were not edited.",
      "files_changed": [
        ".changeset/37413-sqlite-now-default-populated.md",
        "content/docs/protocol/objectql/types.mdx",
        "packages/drivers/driver-sql/src/index.ts",
        "packages/drivers/driver-sql/src/schema-drift.ts",
        "packages/drivers/driver-sql/src/sql-driver-37413-now-default-populated.test.ts",
        "packages/drivers/driver-sql/src/sql-driver-column-creation.ts",
        "packages/drivers/driver-sql/src/sql-driver-rotation.ts",
        "packages/drivers/driver-sql/src/sql-driver-schema-sync.ts",
        "packages/drivers/driver-turso/src/remote-transport.ts",
        "packages/drivers/driver-turso/src/turso-driver.ts",
        "packages/drivers/driver-turso/src/turso-remote-default-parity.test.ts",
        "packages/drivers/driver-turso/src/turso-remote-not-null.test.ts"
      ],
      "security_findings": "none"
    }

    Generated by Claude Code

  11. objectstack-fleet commented on Nov 26, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6CbdHk3orAeensH6EzS

    Close-out · area o5-D · 2026-11-26T09:38Z
    Delivered by PR #37469 (merged, e0b0471c9b): a NOW()-defaulted datetime/date/time field added to a populated SQLite table no longer fails the sync on either face. The column is added nullable with no DEFAULT, and the same transaction (local managed and shard doors) or write batch (remote syncSchema / syncSchemasBatch) fills only the NULLs with the DEFAULT's own instant. Drift reports set_column_default (safe, applied locally by the table rebuild) and tighten_not_null under storage.notNull (destructive). The remote face answers needs-table-rebuild. Clause-②: yes (widening): three new driver-sql exports. L1 ACCEPT 7187416118, delta contract review PASS 7187404230.
    Remaining, all open:

  12. removed
    pm:dispatched
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:datadomain:datafindingpriority:p1

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions