Canonicalise DEFAULT / ON UPDATE / CHECK via vitess#17
Merged
Conversation
…byte-compare Previously column-default and CHECK comparisons were either byte-equal (ptrEq) or relied on `lower + strip whitespace + strip backticks`, which let plenty of semantically-equal SQL trip the diff: CURRENT_TIMESTAMP vs current_timestamp() (1+2) vs 1+2 a > 0 vs a>0 CHECK (`a` > 0) vs CHECK (a > 0) New diff/expr.go gives us: - canonicalExpr: parse `SELECT <s>` with vitess and return the lower-cased restore of the result expression. - equalExpr / equalExprPtr: byte-compare first, then canonicalise both sides on mismatch and compare again. Falls back to byte equality if either side fails to parse, so weird literals don't silently lie. - equalCheckDef: split `CHECK (expr) [NOT ENFORCED]` into expr + suffix, run expr through equalExpr, compare suffix case-insensitively. - looseEqual: the surviving `(col1, col2)` PRIMARY KEY / UNIQUE body comparison; not worth a parse pass. columnEqual now uses equalExprPtr for Default / OnUpdate / Generated (the latter was previously a byte-compare too — same fix). The old constraint normaliser is gone; replaced by the CHECK-aware path and looseEqual fallback. 13 new unit tests in diff/expr_test.go cover the patterns above. All existing tests / scenarios / sample-DB round-trips (Chinook, employees, sakila) still pass. TODO.md: tick the default-normalisation and CHECK-normalisation items; also mark CI workflow and .golangci.yml as done since they shipped weeks ago and the entries were stale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
==========================================
+ Coverage 38.66% 40.20% +1.54%
==========================================
Files 24 25 +1
Lines 1570 1634 +64
==========================================
+ Hits 607 657 +50
- Misses 843 852 +9
- Partials 120 125 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5 tasks
winebarrel
added a commit
that referenced
this pull request
May 2, 2026
Four inline comments. Two typo nits, two flow consistency fixes.
Typos
- parser/directive.go:415 — comment for stripUntilAfterBacktickedName
contained a curly close-quote (\`name\“) instead of a backtick.
Replaced. (Copilot #1.)
- diff/rename_test.go:390 — comment said "RenameFrm"; should be
"RenameFrom". Fixed. (Copilot #2.)
parser/directive.go (flow consistency)
- ValidateDirectives now goes through the same
reduceLeadingBlocks + multi-line block state path the extractors
use, so a malformed directive after `/* header */` or after
`*/` on the same multi-line block-close line still errors at
validation time. Without this, the validator and extractor
disagreed on what counts as a "directive line", letting bad
directives slip past validation and be silently ignored.
(Copilot #3.)
- ExtractStmtRenameFrom and ExtractInlineRenames re-process the
suffix after a multi-line `*/` close on the same line, so
`*/ -- myschema:renamed-from old` still attaches. Previously
the code cleared inBlock and `continue`'d, dropping the
directive. (Copilot #4.)
Tests
- TestValidateDirectivesAfterLeadingBlockComment
- TestValidateDirectivesAfterMultiLineBlockClose
- TestExtractStmtRenameFromMultiLineBlockCloseSameLineAsDirective
- TestExtractInlineRenamesMultiLineBlockCloseSameLineAsDirective
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes the two top-priority "silent diff" items in TODO.md. Previously column-default and CHECK comparisons were either byte-equal (
ptrEq) or relied onlower + strip whitespace + strip backticks, so plenty of semantically-equal SQL tripped the diff:CURRENT_TIMESTAMPcurrent_timestamp()(1+2)1+2a > 0a>0CHECK (\a` > 0)`CHECK (a > 0)Implementation (
diff/expr.go)canonicalExpr(s)— parseSELECT <s>with vitess, return lowercased restore of the result expressionequalExpr/equalExprPtr— byte-compare first, then canonicalise both sides on mismatch; fall back to byte equality if either side fails to parseequalCheckDef— splitCHECK (expr) [NOT ENFORCED]into expr + suffix, normalise expr throughequalExpr, compare suffix case-insensitivelylooseEqual— the surviving(col1, col2)PRIMARY KEY / UNIQUE body comparisoncolumnEqualnow usesequalExprPtrfor Default / OnUpdate / Generated (the latter was previously a byte-compare too — fixed by the same change).Test plan
diff/expr_test.gocover identical, casing, spacing, parens, NULL/TRUE/FALSE, paren-wrapping, NOT ENFORCED suffix, and unparseable-fallback pathsmake test(parser + diff + catalog round-trip + YAML harness)make test-scenariogolangci-lintMisc
TODO.md: tick the default-normalisation and CHECK-normalisation items; also mark CI workflow and
.golangci.ymlas done since they shipped earlier and the entries were stale.🤖 Generated with Claude Code