Skip to content

fix(sql): attach dialect-default temporal fsp when catalogs omit it - #290

Merged
huyplb merged 1 commit into
mainfrom
cursor/critical-bug-management-dbdf
Aug 22, 2026
Merged

fix(sql): attach dialect-default temporal fsp when catalogs omit it#290
huyplb merged 1 commit into
mainfrom
cursor/critical-bug-management-dbdf

Conversation

@cursor

@cursor cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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_type drops (6) for the default typmod), bare Oracle TIMESTAMP, and SQL Server datetime / default datetime2.

Concrete trigger: Postgres column created_at timestamp storing 12:00:00.123456 → migrate to MySQL created bare datetime (= fsp 0) → value became 12:00:00.

Root cause

PR #286 preserved explicit fsp in shapeCanonical, but catalogs often omit the parenthetical when the engine default applies. Parse left length unset; MySQL render then emitted bare datetime/time.

Fix

  • withDefaultTemporalFsp helper
  • Postgres / Redshift / DuckDB / Oracle / Db2: bare temporal → default fsp 6 (Db2: TIMESTAMP only)
  • SQL Server: datetime→3, smalldatetime→0, bare datetime2/time/datetimeoffset→7
  • MySQL bare datetime stays fsp 0 (correct for that engine)

Validation

  • npx vitest run packages/sql/src/modules/type-mapping.test.ts — 18 passed
  • npx vitest run packages/sql — 736 passed, 2 expected fail
Open in Web View Automation 

Note

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_type bare timestamp, Oracle TIMESTAMP, SQL Server datetime / default datetime2). Those used to render as MySQL datetime (fsp 0).

Adds withDefaultTemporalFsp and applies engine defaults on parse: 6 for Postgres, Redshift, DuckDB, Oracle, and Db2 TIMESTAMP; SQL Server datetime→3, smalldatetime→0, bare datetime2/time/datetimeoffset→7. MySQL bare datetime stays unsized (true fsp 0).

canonicalEquals now treats Postgres timestamp as timestamp(6).

Reviewed by Cursor Bugbot for commit c010d58. Bugbot is set up for automated code reviews on this repo. Configure here.

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>
@huyplb
huyplb marked this pull request as ready for review August 22, 2026 14:16
@huyplb
huyplb merged commit ab46ca0 into main Aug 22, 2026
10 checks passed
@huyplb
huyplb deleted the cursor/critical-bug-management-dbdf branch August 22, 2026 14:16
@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Bugbot couldn't run - usage limit reached

Bugbot 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants