fix(sql): attach dialect-default temporal fsp when catalogs omit it - #290
Merged
Conversation
Postgres format_type and similar catalogs omit (6) for default timestamp/time precision. Parsing left length unset, so MySQL/MariaDB migrate emitted bare datetime/time (fsp 0) and silently truncated sub-seconds. Same gap for bare Oracle TIMESTAMP and SQL Server datetime/datetime2 defaults. Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
Contributor
Author
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_883d0a67-2709-4cec-9c2b-1163879274c6) |
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.
Bug and impact
Cross-dialect migrate to MySQL/MariaDB still truncated fractional seconds when the source type string omitted precision — the common case for Postgres
timestamp/timestamptz/time(format_typedrops(6)for the default typmod), bare OracleTIMESTAMP, and SQL Serverdatetime/ defaultdatetime2.Concrete trigger: Postgres column
created_at timestampstoring12:00:00.123456→ migrate to MySQL created baredatetime(= fsp 0) → value became12:00:00.Root cause
PR #286 preserved explicit fsp in
shapeCanonical, but catalogs often omit the parenthetical when the engine default applies. Parse leftlengthunset; MySQL render then emitted baredatetime/time.Fix
withDefaultTemporalFsphelperdatetime→3,smalldatetime→0, baredatetime2/time/datetimeoffset→7datetimestays fsp 0 (correct for that engine)Validation
npx vitest run packages/sql/src/modules/type-mapping.test.ts— 18 passednpx vitest run packages/sql— 736 passed, 2 expected failNote
Medium Risk
Changes how temporal types are parsed and rendered across dialects, which can alter generated DDL and data precision on migrate. Defaults are engine-correct but any mismatch would still truncate or widen fractional seconds.
Overview
Stops cross-dialect migrate from silently dropping fractional seconds when the source catalog omits precision (Postgres
format_typebaretimestamp, OracleTIMESTAMP, SQL Serverdatetime/ defaultdatetime2). Those used to render as MySQLdatetime(fsp 0).Adds
withDefaultTemporalFspand applies engine defaults on parse: 6 for Postgres, Redshift, DuckDB, Oracle, and Db2TIMESTAMP; SQL Server datetime→3, smalldatetime→0, bare datetime2/time/datetimeoffset→7. MySQL baredatetimestays unsized (true fsp 0).canonicalEqualsnow treats Postgrestimestampastimestamp(6).Reviewed by Cursor Bugbot for commit c010d58. Bugbot is set up for automated code reviews on this repo. Configure here.