fix(codegen-ts): @autoSet and plain field.timestamp now honor timestampMode - #281
Merged
Conversation
…mpMode timestampMode:"date" already worked for the base Drizzle column type (column-mapper.ts's mapColumnType) but two call sites still hardcoded string-shaped output regardless: 1. drizzle-schema.ts's @autoset suffix always emitted .$defaultFn(() => new Date().toISOString()) -- a string -- into a column that's mode:"date" (expects a Date), a hard tsc failure ("Type 'string' is not assignable to type 'Date | SQL<unknown>'"), cascading into every generated insert/update query touching the field. 2. zod-validators.ts's FIELD_SUBTYPE_TIMESTAMP case in zodFieldExpr, plus its own 3 separate @autoset call sites, always emitted z.string() / a string-returning transform -- disagreeing with the Drizzle column even for a PLAIN (non-autoSet) timestamp field once timestampMode:"date" is set, not just @autoset ones. Both now branch on ctx.timestampMode: "date" -> new Date() / z.date() (unchanged), "string" (default) -> the original .toISOString()/z.string() behavior, byte-identical to before for every existing caller that doesn't opt in. field.date/field.time stay z.string() unconditionally -- calendar date/time-of-day are inherently string-shaped on the wire, not governed by timestampMode (which is specifically about field.timestamp's instant representation). Not touched: zodScalarFor() (used for field.map's valueType) still returns z.string() for a timestamp-typed map value regardless of timestampMode -- narrower, unverified edge case, flagged rather than guessed at. Reported and reproduced against an adopting project: real entity, real `meta gen`, real `tsc --noEmit` failure before this fix, clean after. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7jsHCMNVmaXu883UFsh1e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to #279 (the serial-identity fix, same adopting-project report). timestampMode:"date" worked for the base Drizzle column but not for @autoset's $defaultFn (hardcoded .toISOString() into a Date-typed column — hard tsc failure) or for zod-validators.ts's FIELD_SUBTYPE_TIMESTAMP case (z.string() regardless of mode, even for plain non-autoSet fields). Both now branch on ctx.timestampMode; unchanged for every existing string-mode caller. bun test: 1040 pass, 0 fail. tsc clean.