Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 6a47ef9

Browse files
authored
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
1 parent 4857995 commit 6a47ef9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

session_schema.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,15 @@ func (session *Session) Sync2(beans ...interface{}) error {
344344
}
345345
}
346346
}
347+
347348
if col.Default != oriCol.Default {
348-
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
349-
tbName, col.Name, oriCol.Default, col.Default)
349+
if (col.SQLType.Name == core.Bool || col.SQLType.Name == core.Boolean) &&
350+
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
351+
(strings.EqualFold(col.Default, "false") && oriCol.Default == "0")) {
352+
} else {
353+
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
354+
tbName, col.Name, oriCol.Default, col.Default)
355+
}
350356
}
351357
if col.Nullable != oriCol.Nullable {
352358
engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v",

session_schema_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,16 @@ func TestSync2_2(t *testing.T) {
332332
assert.True(t, tableNames[table.Name])
333333
}
334334
}
335+
336+
func TestSync2_Default(t *testing.T) {
337+
type TestSync2Default struct {
338+
Id int64
339+
UserId int64 `xorm:"default(1)"`
340+
IsMember bool `xorm:"default(true)"`
341+
Name string `xorm:"default('my_name')"`
342+
}
343+
344+
assert.NoError(t, prepareEngine())
345+
assertSync(t, new(TestSync2Default))
346+
assert.NoError(t, testEngine.Sync2(new(TestSync2Default)))
347+
}

0 commit comments

Comments
 (0)