THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

Don't warn when bool column default is 1 but not true (#1447)

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

* fix default case sensitive
tags/v0.7.9
Lunny Xiao GitHub 1 month ago
parent
commit
6a47ef9b49
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions
  1. +8
    -2
      session_schema.go
  2. +13
    -0
      session_schema_test.go

+ 8
- 2
session_schema.go View File

@@ -344,9 +344,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) &&
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
(strings.EqualFold(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",


+ 13
- 0
session_schema_test.go View File

@@ -332,3 +332,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)))
}

Loading…
Cancel
Save