Skip to content

Fix MySQL 8.0.19+ integer display width compatibility#89

Merged
hidu merged 1 commit intohidu:masterfrom
metowolf:fix/mysql8-display-width
Oct 28, 2025
Merged

Fix MySQL 8.0.19+ integer display width compatibility#89
hidu merged 1 commit intohidu:masterfrom
metowolf:fix/mysql8-display-width

Conversation

@metowolf
Copy link
Copy Markdown
Contributor

Summary

This PR fixes the false positive schema differences when comparing between MySQL 5.7 and MySQL 8.0.19+, addressing issue #78.

Problem

MySQL 8.0.19+ deprecated and removed the display width for integer data types:

  • MySQL 5.7: int(11), bigint(20), tinyint(1)
  • MySQL 8.0.19+: int, bigint, tinyint

This causes constant false positives when syncing schemas between different MySQL versions, as the tool reports differences even though the column definitions are functionally equivalent.

Solution

Added a normalizeIntegerType() function that:

  • Removes display width from integer types for consistent comparison
  • Preserves type modifiers like unsigned, zerofill, unsigned zerofill
  • Handles all integer types: tinyint, smallint, mediumint, int, bigint
  • Case-insensitive matching for robustness

Updated FieldInfo.Equals() to use normalized type comparison, ensuring int(11) and int are treated as equivalent.

Changes

  • internal/util.go: Add normalizeIntegerType() function with comprehensive documentation
  • internal/db.go: Update FieldInfo.Equals() to use normalized integer type comparison
  • internal/util_test.go: Add 30 unit tests covering all integer types and edge cases
  • internal/field_test.go: Add 10 integration tests for field comparison scenarios

Test Coverage

All tests pass with comprehensive coverage:

  • Basic integer type normalization (int, bigint, tinyint, etc.)
  • Type modifiers (unsigned, zerofill, unsigned zerofill)
  • Cross-version compatibility scenarios
  • Non-integer types (varchar, text, etc.) remain unchanged
  • Case-insensitive matching

Closes

Fixes #78

🤖 Generated with Claude Code

MySQL 8.0.19+ deprecated display width for integer types (int(11) -> int),
causing false positive schema differences. Add normalizeIntegerType()
function to handle this compatibility issue.

- Add normalizeIntegerType() in util.go to normalize integer types
- Update FieldInfo.Equals() to use normalized comparison
- Add comprehensive unit tests for the new function
- Add integration tests in field_test.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@hidu hidu merged commit b8fd921 into hidu:master Oct 28, 2025
1 check passed
@metowolf metowolf deleted the fix/mysql8-display-width branch October 28, 2025 04:27
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.

MySQL 8.0.19+ 与MySQL 5.7.x对比

2 participants