Skip to content

fix constraint diffing#657

Merged
morgo merged 1 commit into
block:mainfrom
morgo:fix-constraint-diff
Mar 11, 2026
Merged

fix constraint diffing#657
morgo merged 1 commit into
block:mainfrom
morgo:fix-constraint-diff

Conversation

@morgo
Copy link
Copy Markdown
Collaborator

@morgo morgo commented Mar 11, 2026

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.
Further notes in https://github.com/block/spirit/blob/main/.github/CONTRIBUTING.md

The auto-named constraints generate random string names. The fix is to remove them from compares and look at the constraint definition specifically.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves schema diffing for CREATE TABLE constraints by avoiding spurious diffs when CHECK constraints are logically equivalent but end up with different MySQL auto-generated names due to expression normalization differences (e.g., charset introducers).

Changes:

  • Add constraint matching logic in diffConstraints to pair equivalent constraints across differing names and skip DROP/ADD.
  • Refactor constraint equality to reuse a new constraintsEqualIgnoreName helper.
  • Add regression tests covering charset-introducer normalization and differing-name/differing-expression behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/statement/diff.go Adds expression-equivalent constraint pairing across names and introduces constraintsEqualIgnoreName.
pkg/statement/diff_test.go Adds tests to ensure no diff for normalized CHECK expressions with different names, and still diff when expressions differ.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/statement/diff.go
Comment thread pkg/statement/diff_test.go
@morgo morgo enabled auto-merge March 11, 2026 21:55
@morgo morgo merged commit f9b2361 into block:main Mar 11, 2026
14 checks passed
@morgo morgo deleted the fix-constraint-diff branch March 11, 2026 21:56
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.

4 participants