fix(sql): flag DECIMAL(p) scale-0 narrowing (migrate + revert) - #277
Merged
Conversation
SQL defines DECIMAL(p) as DECIMAL(p,0). Migration pre-flight and History revert both required an explicit scale on both sides before flagging a reduction, so numeric(10,2) → numeric(10) truncated fractional digits with no NARROWING_TYPE_CHANGE warning and classified the revert as safe. 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_4c4d83ea-007a-4590-833c-382f6bc92627) |
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
DECIMAL(p)/NUMERIC(p)meansDECIMAL(p,0)in SQL. Migrating or reverting a column fromnumeric(10,2)→numeric(10)truncates fractional digits, but:findNarrowingTypeChanges) skipped the scale check when the desired type omitted scale, so there was noNARROWING_TYPE_CHANGEwarning.parseTypeText) stored the sole argument aslength, so scale comparison never ran and the revert was classifiedsafe— Execute needed no data-loss confirmation.Concrete trigger: Original has
amount NUMERIC(10), Target hasamount NUMERIC(10,2)with values like19.99. Syncing Target to Original (or reverting to that version) rounds away cents without warning.Root cause
Both checkers required
scaleto be defined on both sides. The omitted-scale form leftscaleundefined (tokenizer single-arg →lengthin reverse parsing), so the reduction was invisible to the safety net. ExplicitNUMERIC(10,0)was already flagged.Fix
isNarrowing: treat missing scale as0when precision is present.parseTypeText: mapnumeric/decimal/number/decsingle-arg forms to{ precision, scale: 0 }.Validation
numeric(10,2)→numeric(10).npx vitest run packages/sql— 700 passed, 2 expected fail.Note
Medium Risk
Changes how narrowing and revert-risk are classified for decimal columns; behavior is safer (more warnings) but could affect migrate/revert UX where omitted-scale types were previously treated as non-narrowing.
Overview
Treats
DECIMAL(p)/NUMERIC(p)as(p, 0)so fractional-digit loss is no longer invisible when scale is omitted on one side of a comparison.Migrate pre-flight (
isNarrowinginmigration-validation.ts): when comparing decimal types, missing scale is now 0 if precision is set, sonumeric(10,2)→numeric(10)surfaces aNARROWING_TYPE_CHANGEwarning instead of being skipped.History revert (
parseTypeTextinreversal.ts): single-argumentnumeric/decimal/number/decforms are parsed as{ precision, scale: 0 }rather thanlength, soclassifyReversalmarksnumeric(10,2)→numeric(10)as lossy (scale 2 → 0) instead of safe.Tests cover parsing, migrate narrowing, and revert classification for these cases.
Reviewed by Cursor Bugbot for commit c7c549c. Bugbot is set up for automated code reviews on this repo. Configure here.