Skip to content

Commit a2cb3aa

Browse files
fix(driver-sql, objectql, metadata-protocol): publishing a field change on a live object brings its table to the declaration (#32848)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu1SdwSJeacEmsneiyCVnM74)_ Fixes #32590 Clause-②: yes (widening) — new public `SqlDriver.applyPublishedColumnChanges` and `ObjectQL.applyPublishedColumnChanges`, a new `widen_date_to_datetime` drift op, an optional `MetadataHostEngine.applyPublishedColumnChanges` member and the new `object-column-changes-not-applied` advisory rule Metadata-protocol: none ## 维护者速读 - 改了什么:对已上线对象发布字段变更时,表现在会跟着声明一起改。`date` → `datetime` 会把列扩宽(Postgres 改成 `timestamptz`,MySQL 改成 `DATETIME(3)`),声明 `storage: { notNull: false }` 会放开 NOT NULL。表跟不上的列变更会在发布回答里返回一条 warning advisory。 - 为什么改:以前发布只改元数据、不改表。`date` → `datetime` 之后写进去的时间会被丢掉(数据丢失);字段改成非必填之后,不带这个字段的新建仍然被数据库拒绝。 - 风险与回滚:只有发布对象时才会改表,而且只做不会丢数据的列变更(扩宽、放开约束、varchar 加宽、去掉运行时默认值)。启动、`syncSchema` 和生产环境的 boot 姿态都不变。Postgres 改列类型时,会在发布请求内持表锁重写整张表;等锁最多 5 秒,等不到就跳过这项变更,发布返回 advisory。回滚就是 revert 本 PR,已经扩宽的列保持扩宽,读写不受影响。 - 先看:`packages/drivers/driver-sql/src/sql-driver-schema-sync.ts`(`isPublishedColumnChange` 选哪些变更、`widenDateColumnToDatetime` 的 PG/MySQL DDL);`packages/drivers/driver-sql/src/schema-drift.ts`(新的 `safe` 扩宽项、显式 `notNull: false` 项);`packages/metadata-protocol/src/protocol-registry-hydration.ts`(`ensureObjectStorage` 里的发布门调用和 advisory)。 - 两分钟验证:运行 `pnpm --filter @objectstack/runtime exec vitest run src/domains/meta-object-publish-column-changes.test.ts`,应看到 3 passed(时间保留、不带标题的新建成功、number→text 返回 409)。 - 需要你做的:无,席位落地。 Branch: `claude/project-thread-i1qy0g` (the harness-assigned card-thread branch). ## What changes Publishing a changed object used to update its metadata and leave its table as it was. Two changes that the field-type table (`content/docs/data-modeling/field-type-decision-tree.mdx`) says "pass cleanly" did not pass at the table. Both were reproduced on better-sqlite3 and Postgres 16 through `syncSchema`, the call the publish makes: - **`date` → `datetime` on a table with rows.** Postgres and MySQL kept the `date` column, so every time written after the publish was dropped at the column. On SQLite the field stayed registered as a date, so the read cut the value to its day. That registry was only ever added to, and a retyped field ended up in both sets. - **`required: true` → `false` with `storage: { notNull: false }`.** The column kept its NOT NULL, so every create that omitted the field was refused by the database. The fix, per change kind as the table reads: - **`@objectstack/driver-sql`.** - `registerManagedObjectMetadata` and `registerExternalObject` now rebuild the date, datetime and time registries from the declaration on every registration. - The differ has a new `widen_date_to_datetime` op, category `safe`, on Postgres and MySQL only. SQLite has no temporal column type to widen. - Its in-place arm re-reads the column first and alters it only while it is still `date`: - Postgres, in one transaction that bounds the lock wait (`SET LOCAL lock_timeout`, 5 s), takes the table lock and re-reads the column, so a second server applying the same publish finds nothing left to do: `ALTER COLUMN … TYPE timestamptz USING (col::timestamp AT TIME ZONE 'UTC')`, with the declared default restated. Behind a lock held longer, the entry is skipped with a `warn` line naming the reason. - MySQL, with no transaction (MySQL DDL commits implicitly): `MODIFY … DATETIME(3)`, keeping nullability and the default. - A NOT NULL column whose field declares `storage: { notNull: false }` in words is now reported whatever `required` says, and its message names the declaration. It stays `needs_confirm` (ADR-0113 D5). - The new public `SqlDriver.applyPublishedColumnChanges(object)` diffs one object and applies its `safe` column entries plus that explicit relax. It never applies index entries, any other `needs_confirm` entry, or a `destructive` one. It returns `{ applied, skipped }`. - **`@objectstack/objectql`.** The new `ObjectQL.applyPublishedColumnChanges(objectName)` calls that driver door. Its body sits in `engine-compatibility-api.ts`, beside `syncObjectSchema`. It answers `undefined` for a federated object or a driver without the door. `syncObjectSchema` is unchanged, as is its spec contract (`IObjectQLEngine.syncObjectSchema?(name): Promise<void>`, "only create what is absent"). - **`@objectstack/metadata-protocol`.** `ensureObjectStorage` calls it after the additive sync, so every door that publishes an object gets the column half. `MetadataHostEngine` declares the member as optional. A change the datasource cannot apply, or a failure while applying, has its own `catch`: it is logged at `error` and answered as one `object-column-changes-not-applied` warning on `advisories`, in the shape of `object-storage-sync-refused`. The publish still succeeds. - **`@objectstack/driver-turso`.** The REMOTE face's `REMOTE_FACE_ANSWERS` row for the new member is `inherited`, since the body reaches the face's own `detectManagedDrift` / `applyMigrationEntries`. `REMOTE_DRIFT_OP_ANSWERS` answers the new op `needs-table-rebuild`; the SQLite differ never emits it. **SQLite path used:** there is no `ALTER COLUMN` on SQLite. Nothing needs altering for `date` → `datetime`, because both store canonical text; the registry rebuild is the fix there. The NOT NULL relax goes through `applyMigrationEntries` → `rebuildSqliteTablePatched`, the existing copy-into-a-patched-table rebuild that `os migrate apply` already uses on SQLite. **What the table says needs a migration is still refused at the save:** `number` → `text` answers `409 DESTRUCTIVE_CHANGE` (`field_type_change`) from `detectDestructiveObjectChanges`, unchanged and now pinned end to end. `text` → `textarea` / `markdown` / `html` / `code` needs no column change, because the text family shares one unkeyed `TEXT` column. ## Tests - `packages/drivers/driver-sql/src/sql-driver-published-column-changes.test.ts` (36 cases). Differ half: every dialect's spelling, including the silent controls (no SQLite widen, no false positive over `timestamptz`, the undeclared NOT NULL shapes unchanged). Live half: SQLite, live Postgres and live MySQL cells through `declareDialectCell`. Each cell pins: - the additive sync alone changes nothing (non-vacuity); - exactly the expected entries are applied and nothing is skipped; - the columns follow the declaration; - an ISO datetime written after the publish reads back with its time; - a day stored before the publish keeps its day; - a create without the field succeeds; - the undeclared NOT NULL is left alone; - a second publish finds nothing to apply. A live Postgres case holds the table from another session: the publish gives up after the 5 s bound, reports the widening skipped, logs the reason and leaves the column `date`; once the lock is released, the next publish applies it. - `packages/runtime/src/domains/meta-object-publish-column-changes.test.ts` (3 cases). Draft save, then `publishMetaItem`, over the real protocol, engine and SQL driver: - `date` → `datetime` keeps the time; - `required` → `false` with `storage.notNull: false` lets a create omit the field; - `number` → `text` is refused 409 at the save, with the table and the served object unchanged. - `packages/objectql/src/federated-injected-column-readers.test.ts`: one census row for the new body's `isFederatedObject()` use. ## Acceptance notes - **ADR-0113 D5 reading.** The explicit `storage: { notNull: false }` entry keeps D5's `needs_confirm`, so dev `autoMigrate: 'safe'` still never applies it at boot. Only the publish of that declaration (the deliberate relax D5 names) and `os migrate apply` apply it. `os migrate apply` already applied `needs_confirm` together with `safe`, which is unchanged. A NOT NULL with no `storage.notNull` written either way is NOT relaxed by the publish. Example: v1 `storage: { notNull: true }`, then v2 omits `storage`. That column keeps its NOT NULL and the boot keeps warning `needs_confirm` as before; the publish answer does not mention it. - **Same class, applied by the same door:** the publish also applies the existing `safe` column entries for the published object, `widen_varchar` and `drop_column_default`. - **Lock and time.** On Postgres the type change rewrites the table inside the publish request under `ACCESS EXCLUSIVE`, so a large table makes that publish as slow as the rewrite. The wait for that lock is bounded at 5 s (`SET LOCAL lock_timeout`), because a waiting ACCESS EXCLUSIVE request queues every later statement on the table behind it. Behind a session holding the table longer, the widening is skipped with a `warn` line naming the reason, the publish answers its `object-column-changes-not-applied` advisory, and the next publish or `os migrate apply` applies it. The door goes through the public `applyMigrationEntries` so the Turso REMOTE face answers for itself. Like any explicit run, that closes the concurrent-index deferral window (#31901), so the next concurrent build waits its bound once more. - **Stored days become midnight UTC.** This is explicit on Postgres (`AT TIME ZONE 'UTC'`, so the session zone cannot move it) and native on MySQL's zone-naive `DATETIME`. Measured with the process in `America/New_York` and both servers at `+08:00`. - **Turso REMOTE face:** an entry that needs a table rebuild (a SQLite `relax_not_null`) comes back `skipped` and reaches the advisory and the `error` line. The face's row is pinned by `turso-remote-inherited-members.test.ts`; that end-to-end outcome on a remote transport is not pinned by a new test. - **Boot order:** a boot that runs before the publish still prints the previous state's drift warning once. The publish then applies the change. - **Out of scope, reported to the seat (not fixed here):** `datetime` → `date`, the reverse change the table also says passes cleanly, reads a day early on Postgres when the server zone is ahead of UTC. A value written `2026-11-12` after the change reads back `2026-11-11`; the column stays `timestamptz`. The result is identical on the base commit, so it predates this diff. SQLite and MySQL read correctly. ## Verification Head `038057cd`, the review round's commit on top of `58501571`. The branch was merged with `origin/main` at `2f80f289` before this PR and has not chased main since; #32690 is in that base. **Reproduced before the fix.** Base `ee230a25` (two commits after the claim's `9af07668ed`), through `syncSchema` v1 → v2, the storage call the publish makes: - better-sqlite3: an update to `2026-11-13T01:00:00.000Z` read back `2026-11-13`. A create without `title` was refused `SQLITE_CONSTRAINT_NOTNULL`. - Postgres 16: `start_date` was still `date` after the v2 sync, and the same update read back `2026-11-13`. The create was refused `23502` (not-null violation on `title`). **Rig.** Live Postgres 16 and MySQL 8.0.46 on this box, both servers at `+08:00`. The test process ran with `TZ=America/New_York` and `OS_EXPECT_LIVE_DIALECT_MATRIX=1`, so a live cell cannot skip. **Pins on this head.** - `pnpm --filter @objectstack/driver-sql exec vitest run src/sql-driver-published-column-changes.test.ts`: 36 passed (sqlite, live pg and live mysql cells, plus the live pg lock case, which waits out the 5 s bound). - `pnpm --filter @objectstack/runtime exec vitest run src/domains/meta-object-publish-column-changes.test.ts`: 3 passed. The same three cases also passed against live Postgres through a temporary, uncommitted copy of the file that pointed its driver at Postgres; the copy was deleted and is not in this diff. **Full suites,** after the main merge and a full `pnpm build` (119 of 119): - driver-sql with live pg and mysql: 6375 passed, 1 failed, 5 skipped on `038057cd`. The one red is `sql-driver-11565-row-byte-budget` "reports InnoDB page-limit refusals with the page limit, not the row budget" on live MySQL. It fails the same way on the base `ee230a25` source with this box's Ubuntu MySQL 8.0.46, so it is environmental and not this diff. - On `58501571`: objectql 12591 passed. metadata-protocol 22786 passed, 36 skipped. runtime 10250 passed, 19 skipped. The review round changes only driver-sql source, its pin and the changeset, so on `038057cd` driver-sql was rebuilt and its suite above, driver-turso (2523 passed, 34 skipped) and the runtime pin (3 passed) were run again. - `typecheck` for driver-sql, driver-turso, objectql, metadata-protocol and runtime (runtime's includes `check:test-typecheck`): 0 errors; driver-sql again on `038057cd`: 0 errors. **Ablations.** Each one put the old behaviour back with `scripts/ablation-replace.mjs`, ran the pin and saw it go red, then restored. Each restore printed blob == HEAD with `git diff HEAD` empty. A1 to A4 and B1 ran on `58501571`; A5 ran on `038057cd`. | # | Old behaviour put back | File | Red | |---|---|---|---| | A1 | the explicit `storage.notNull: false` relax is not selected (`return false && …`) | `sql-driver-schema-sync.ts` `isPublishedColumnChange` | 12 of 34 | | A2 | the Postgres / MySQL widen arm never runs | `sql-driver-schema-sync.ts` `applyDriftOpInPlace` | 10 of 34 | | A3 | the date registry accumulates again | `sql-driver-rotation.ts` | 6 of 34 | | A4 | the differ's widen branch never matches | `schema-drift.ts` | 10 of 34 | | B1 | the publish never calls the door (`columns = undefined;`) | `protocol-registry-hydration.ts` | 1 of 3 (runtime) | | A5 | the Postgres lock wait is unbounded again (`lock_timeout` set to `'0'`) | `sql-driver-schema-sync.ts` `widenPostgresDateColumn` | 2 of 36 | B1 went through the built package. `ablation-dist-preflight.mjs` proved the call absent from all 22 files in `metadata-protocol/dist`. After the restore and rebuild it proved the call present again, and the three cases were green. Only the NOT NULL case goes red there. On SQLite the `date` → `datetime` half is the registry rebuild, which runs on the additive sync and not through the door. A3 holds that half on all three dialects, and A2 and A4 hold the column widening on Postgres and MySQL. **Driver conformance ledger.** `node scripts/check-driver-conformance.mjs`, before the change and on this head: `66 covered cell(s), 6 in the DEBT ledger, 0 exempt`, and dialect axis `11 of 11`. Nothing moved. This diff adds no case-set and touches no ledger row. **Gates.** - On `038057cd`, for the review round's three files: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack <those paths>` derived 66 families. All 66 exited 0, and `--ran` answered `66 derived famil(ies) accounted for — 66 run, 0 NOT-MEASURED`. - On `58501571`, for the whole diff: 73 derived families, all exited 0, `--ran` `73 run, 0 NOT-MEASURED`. - `pnpm lint`: exit 0, and `node scripts/check-nul-bytes.mjs`: exit 0, both on `58501571`. - `check-plugin-teardown-shape --self-test` needs its pinned fixture commit in the shallow clone. It was fetched first (`git fetch --depth=1 origin 621a487`), so the family is a reading, not an exit 3. **Merge before the queue.** `origin/main` at `5fb79bc0` was merged once more as `b67fa33a` (first-parent K = 18 since `2f80f289`, with language-pack changes in between), with no conflict. On `b67fa33a`: a full `pnpm build` (119 of 119). `dispatch-gates --commands` for this PR's six files in the packages main also moved (metadata-protocol, objectql, runtime) derived 62 families; all 62 exited 0, and `--ran` answered `62 run, 0 NOT-MEASURED`. metadata-protocol 22790 passed, 36 skipped; objectql 12615 passed; typecheck for metadata-protocol, objectql and runtime 0 errors; pins 36 of 36 (driver-sql, live pg and mysql) and 3 of 3 (runtime). CI on `b67fa33a` finished with no failure. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgWwN7doasrBSHNAPGB)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWwN7doasrBSHNAPGB <!-- signed: domain:server#4 · os-sales · session_01L6bhgWwN7doasrBSHNAPGB --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b811f6a commit a2cb3aa

14 files changed

Lines changed: 1057 additions & 17 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/driver-sql': patch
3+
'@objectstack/driver-turso': patch
4+
'@objectstack/objectql': patch
5+
'@objectstack/metadata-protocol': patch
6+
---
7+
8+
fix(driver-sql,objectql,metadata-protocol): publishing a field change on a live object brings the table to the declaration — `date` → `datetime` keeps the time, and `storage: { notNull: false }` drops the NOT NULL
9+
10+
Clause-②: yes (widening) — new public `SqlDriver.applyPublishedColumnChanges` and `ObjectQL.applyPublishedColumnChanges`, a new `widen_date_to_datetime` drift op, an optional `MetadataHostEngine.applyPublishedColumnChanges` member and the new `object-column-changes-not-applied` advisory rule
11+
Metadata-protocol: none
12+
13+
Publishing a changed object used to update the metadata and leave its table as it was. Two changes the field-type table says pass cleanly did not:
14+
15+
- **`date` → `datetime` on a table with rows.** Every time of day written after the publish was lost. Postgres and MySQL kept the `date` column, and the SQLite driver kept the field registered as a date, so the read cut the value to its day. The publish now widens the column in place (Postgres `timestamptz`, MySQL `DATETIME(3)`; each stored day becomes midnight UTC; on Postgres the widening waits at most 5 seconds for its table lock, and behind a lock held longer it is reported as not applied), and the driver re-registers the field's type on every sync, so a value written afterwards reads back with its time on all three dialects.
16+
- **`required: true` → `false` with `storage: { notNull: false }`.** The column kept its NOT NULL, so every create that omitted the field was refused by the database although the declaration said it was optional. The publish now relaxes the column.
17+
18+
How it works:
19+
20+
- **`@objectstack/driver-sql`.** A new `SqlDriver.applyPublishedColumnChanges(object)` applies the `safe` column drift (now including the new `widen_date_to_datetime` op, Postgres and MySQL only) plus one `needs_confirm` entry: a NOT NULL column whose field explicitly declares `storage: { notNull: false }`. That entry is now reported whatever `required` says, and its message names the declaration. It stays `needs_confirm`, so dev `autoMigrate: 'safe'` still never applies it at boot (ADR-0113 D5). A NOT NULL with no `storage.notNull` declared either way is left as it was. Index work is not touched. `syncSchema` and `initObjects` stay additive.
21+
- **`@objectstack/objectql`.** A new `ObjectQL.applyPublishedColumnChanges(objectName)` calls that driver door. It skips a federated object or a driver without the door, and reports what was applied and what was not. `syncObjectSchema` is unchanged.
22+
- **`@objectstack/metadata-protocol`.** Every door that publishes an object (`saveMetaItem` in publish mode, `publishMetaItem`, `publishPackageDrafts` and the others that run `ensureObjectStorage`) calls it after the storage sync. A change the datasource cannot apply, such as a table rebuild over the Turso remote transport, or a failure while applying the changes, is logged at `error` and returned as an `object-column-changes-not-applied` warning on the answer's `advisories`. The publish still succeeds.
23+
- **`@objectstack/driver-turso`.** The remote face inherits the door, so it diffs the remote catalog and returns any entry needing a table rebuild as not applied.
24+
25+
A change the table says needs a migration (for example `number` → `text`) is still refused at the save with `409 DESTRUCTIVE_CHANGE`, as before.

‎packages/drivers/driver-sql/src/schema-drift.ts‎

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,27 @@ export type DriftOp =
188188
* can show the divergence without re-deriving it from the message.
189189
*/
190190
| { type: 'manual_column_type_change'; table: string; column: string; to: string; from: string }
191+
/**
192+
* Widen a `date` column under a field that now declares `datetime` (#32590)
193+
* to the column `createColumn` builds for a `datetime`: `timestamptz` on
194+
* Postgres, `DATETIME(3)` on MySQL. Postgres and MySQL only — SQLite stores
195+
* the canonical text in any declared column type, so its `date` column holds
196+
* a time of day already and nothing is reported there.
197+
*
198+
* The field-type change table promises `date` → `datetime` passes cleanly
199+
* (`content/docs/data-modeling/field-type-decision-tree.mdx`), and this is the
200+
* column half of that promise. Until this op existed the divergence was
201+
* reported by NOTHING, and every write to the field lost its time of day: the
202+
* database casts an instant bound into a `date` column to its calendar day,
203+
* with no error and no warning.
204+
*
205+
* `safe` by the class's own definition — a loosening that cannot lose data
206+
* and cannot fail: every stored day converts (as midnight UTC, the instant
207+
* the canonical form gives a bare day) and no value is refused. A publish of
208+
* the object applies it (`SqlDriver.applyPublishedColumnChanges`), as do dev
209+
* auto-reconcile and `os migrate apply`.
210+
*/
211+
| { type: 'widen_date_to_datetime'; table: string; column: string }
191212
/**
192213
* REPORT ONLY (#12121). The column is a `varchar(n)` under a TEXT-family
193214
* field that declared NO usable bound — the shape `createColumn` emits as
@@ -1087,7 +1108,39 @@ export function diffManagedTable(args: {
10871108
// explicit physical constraint — NOT against `required`, which is the
10881109
// write-time contract and implies nothing about the column) ──────────
10891110
const expectNullable = field.storage?.notNull !== true;
1090-
if (expectNullable && !col.nullable && field.required !== true && fieldName !== ceremonyOwnedNullability) {
1111+
if (expectNullable && !col.nullable && field.storage?.notNull === false && fieldName !== ceremonyOwnedNullability) {
1112+
// [#32590] The author DECLARED the column nullable — `storage: { notNull:
1113+
// false }`, written out, not merely absent. The column constraint is the
1114+
// declaration's to own (ADR-0113 D2), and this is the "deliberately
1115+
// relax" ADR-0113 D5 names, said by the author in so many words: until it
1116+
// is applied, every write that omits the field is refused by the
1117+
// database, `required` notwithstanding. So the entry is reported whatever
1118+
// `required` says (D5's silence is for the legacy shape below, which
1119+
// carries no `storage` at all), and its message says what the declaration
1120+
// says rather than "declares no storage constraint".
1121+
//
1122+
// ⛔ The CATEGORY stays D5's `needs_confirm`, never `safe`: dev
1123+
// auto-reconcile (`autoMigrate: 'safe'`) still does not apply it at
1124+
// boot. What applies it is the publish of this declaration
1125+
// (`applyPublishedColumnChanges`, which selects exactly this entry by
1126+
// the explicit `false`) or `os migrate apply` — both a deliberate act.
1127+
// An ABSENT `storage.notNull` stays the undeclared case below, unchanged.
1128+
out.push({
1129+
kind: 'nullability_mismatch',
1130+
remoteName: table,
1131+
table,
1132+
column: fieldName,
1133+
expected: 'NULL',
1134+
actual: 'NOT NULL',
1135+
severity: 'warning',
1136+
category: 'needs_confirm',
1137+
op: { type: 'relax_not_null', table, column: fieldName },
1138+
message:
1139+
`${table}.${fieldName}: the column is NOT NULL but the metadata declares ` +
1140+
`\`storage: { notNull: false }\`, so the database refuses every write that omits the field. ` +
1141+
`Relaxing the column cannot lose data: publishing the object applies it, or relax it deliberately via "os migrate apply".`,
1142+
});
1143+
} else if (expectNullable && !col.nullable && field.required !== true && fieldName !== ceremonyOwnedNullability) {
10911144
// Column STRICTER than its declaration — and the field is not even
10921145
// write-gated, so an omitting write reaches the DB and dies as a raw
10931146
// driver error instead of a clean validation 400. That surprise is
@@ -1342,6 +1395,46 @@ export function diffManagedTable(args: {
13421395
});
13431396
}
13441397

1398+
// ── base type: a `datetime` field over a `date` column (#32590) ──────
1399+
//
1400+
// `createColumn` gives a `date` field a `date` column, and the additive sync
1401+
// never revisits an existing column, so a field retyped `date` → `datetime`
1402+
// — a change the field-type change table says passes cleanly — keeps its
1403+
// `date` column. On Postgres and MySQL that column is load-bearing: the
1404+
// server casts every instant bound into it to its calendar day, so the
1405+
// field reads back as a bare day and every time of day ever written to it is
1406+
// gone, with no error. Measured on live Postgres 16 on the pre-fix tree:
1407+
// `'2026-11-13T01:00:00.000Z'` written after the publish read back
1408+
// `'2026-11-13'`. SQLite keeps the canonical text whatever the declared
1409+
// column type, so nothing is reported there.
1410+
//
1411+
// `safe` — see the op's own note: the widening keeps every stored day and
1412+
// refuses no value — so a publish of the object applies it.
1413+
if (
1414+
declaredType === 'datetime'
1415+
&& !declaresJsonColumn
1416+
&& (dialect === 'postgres' || dialect === 'mysql')
1417+
&& String(col.type).toLowerCase() === 'date'
1418+
) {
1419+
const widened = dialect === 'mysql' ? 'datetime(3)' : 'timestamptz';
1420+
out.push({
1421+
kind: 'type_mismatch',
1422+
remoteName: table,
1423+
table,
1424+
column: fieldName,
1425+
expected: widened,
1426+
actual: col.type,
1427+
severity: 'warning',
1428+
category: 'safe',
1429+
op: { type: 'widen_date_to_datetime', table, column: fieldName },
1430+
message:
1431+
`${table}.${fieldName}: metadata declares \`datetime\` but the column is \`${col.type}\`, so the ` +
1432+
`database keeps only the calendar day of every value written to it and drops its time of day. ` +
1433+
`Widening the column to \`${widened}\` keeps every stored day (as midnight UTC) and refuses no value: ` +
1434+
`publishing the object applies it, or run "os migrate apply".`,
1435+
});
1436+
}
1437+
13451438
// ── varchar length (only where the dialect enforces it) ──────────
13461439
//
13471440
// `maxLength` must be a POSITIVE INTEGER to be a bound (#11431). Without

‎packages/drivers/driver-sql/src/sql-driver-declared-rename.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const TYPE_DRIFT_OPS: ReadonlySet<DriftOp['type']> = new Set([
6767
'widen_varchar',
6868
'manual_column_type_change',
6969
'manual_widen_varchar_to_text',
70+
'widen_date_to_datetime',
7071
]);
7172

7273
/** The object shape these bodies read: its fields, and its declared indexes for keyedness. */

0 commit comments

Comments
 (0)