added varchar size increment auto sync for mysql in Sync2
This commit is contained in:
parent
a8fba4d3d9
commit
d5819023e7
16
session.go
16
session.go
|
@ -4011,10 +4011,26 @@ func (s *Session) Sync2(beans ...interface{}) error {
|
||||||
engine.LogWarnf("Table %s column %s db type is %s, struct type is %s\n",
|
engine.LogWarnf("Table %s column %s db type is %s, struct type is %s\n",
|
||||||
table.Name, col.Name, curType, expectedType)
|
table.Name, col.Name, curType, expectedType)
|
||||||
}
|
}
|
||||||
|
} else if strings.HasPrefix(curType, core.Varchar) && strings.HasPrefix(expectedType, core.Varchar) {
|
||||||
|
if engine.dialect.DBType() == core.MYSQL {
|
||||||
|
if oriCol.Length < col.Length {
|
||||||
|
engine.LogInfof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||||
|
table.Name, col.Name, oriCol.Length, col.Length)
|
||||||
|
_, err = engine.Exec(engine.dialect.ModifyColumnSql(table.Name, col))
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
engine.LogWarnf("Table %s column %s db type is %s, struct type is %s",
|
engine.LogWarnf("Table %s column %s db type is %s, struct type is %s",
|
||||||
table.Name, col.Name, curType, expectedType)
|
table.Name, col.Name, curType, expectedType)
|
||||||
}
|
}
|
||||||
|
} else if expectedType == core.Varchar {
|
||||||
|
if engine.dialect.DBType() == core.MYSQL {
|
||||||
|
if oriCol.Length < col.Length {
|
||||||
|
engine.LogInfof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||||
|
table.Name, col.Name, oriCol.Length, col.Length)
|
||||||
|
_, err = engine.Exec(engine.dialect.ModifyColumnSql(table.Name, col))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if col.Default != oriCol.Default {
|
if col.Default != oriCol.Default {
|
||||||
engine.LogWarnf("Table %s Column %s db default is %s, struct default is %s",
|
engine.LogWarnf("Table %s Column %s db default is %s, struct default is %s",
|
||||||
|
|
Loading…
Reference in New Issue