don't warn when bool column default is 1 but not true

This commit is contained in:
Lunny Xiao 2019-10-02 11:53:50 +08:00
parent da95db5ddc
commit c68f2b123c
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 21 additions and 2 deletions

View File

@ -339,9 +339,15 @@ func (session *Session) Sync2(beans ...interface{}) error {
}
}
}
if col.Default != oriCol.Default {
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
tbName, col.Name, oriCol.Default, col.Default)
if (col.SQLType.Name == core.Bool || col.SQLType.Name == core.Boolean) &&
((col.Default == "true" && oriCol.Default == "1") ||
(col.Default == "false" && oriCol.Default == "0")) {
} else {
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
tbName, col.Name, oriCol.Default, col.Default)
}
}
if col.Nullable != oriCol.Nullable {
engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v",

View File

@ -307,3 +307,16 @@ func TestSync2_2(t *testing.T) {
assert.True(t, tableNames[table.Name])
}
}
func TestSync2_Default(t *testing.T) {
type TestSync2Default struct {
Id int64
UserId int64 `xorm:"default(1)"`
IsMember bool `xorm:"default(true)"`
Name string `xorm:"default('my_name')"`
}
assert.NoError(t, prepareEngine())
assertSync(t, new(TestSync2Default))
assert.NoError(t, testEngine.Sync2(new(TestSync2Default)))
}