-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix decimal migrate error. #7450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
我在代码里面没有看到automigrate相关的测试内容。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some tests in https://github.com/go-gorm/gorm/blob/master/tests/migrate_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add unit tests for my question?
Signed-off-by: Chise1 <chise123@live.com>
Signed-off-by: Chise1 <chise123@live.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a temporary solution, and the comments need to be handled later.
#7450 (comment)
#7450 (comment)
I think the specific types (decimal/numeric) should be abstracted out and handled by the driver, which may require extending the ColumnType interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where AutoMigrate would always emit an ALTER for decimal/numeric fields even when precision/scale hadn’t changed. It adds targeted precision checks in the migrator and a new test suite to verify correct behavior.
- Added precision-aware logic for
decimal
/numeric
inMigrator.MigrateColumn
- Introduced
TestAutoMigrateDecimal
and helpers to validate no-op versus real ALTERs - Updated
go.mod
to bump GORM and driver versions
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
tests/migrate_test.go | Added testAutoMigrateDecimal , decimalColumnsTest , and TestAutoMigrateDecimal |
tests/go.mod | Bumped gorm.io/gorm to v1.26.1 and related driver versions |
migrator/migrator.go | Enhanced decimal/numeric precision detection to prevent redundant ALTERs |
Comments suppressed due to low confidence (2)
tests/migrate_test.go:2004
- [nitpick] The Go convention is to use uppercase acronyms; rename
modifySql
tomodifySQL
for consistency.
var modifySql []string
tests/migrate_test.go:2028
- [nitpick] Rename
modSql
tomodSQL
to follow Go naming conventions for acronyms.
modSql := testAutoMigrateDecimal(t, t1, t2)
Signed-off-by: Chise1 <chise123@live.com>
Signed-off-by: Chise1 <chise123@live.com>
Signed-off-by: Chise1 <chise123@live.com>
# Conflicts: # tests/go.mod
What did this pull request do?
修复automigrate无法正确识别decimal精度是否变化的问题。
User Case Description
参考issues 7449
如果有一个对象如下:
每次自动同步都会触发