fix #2444 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/xorm/xorm/pulls/2445 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: lijunshi <lijunshi2015@163.com> Co-committed-by: lijunshi <lijunshi2015@163.com>
This commit is contained in:
parent
3bc2ea24f6
commit
c6d05fa553
|
@ -465,7 +465,7 @@ res, err := engine.Transaction(func(session *xorm.Session) (interface{}, error)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
If you want to pull request, please see [CONTRIBUTING](https://gitea.com/xorm/xorm/src/branch/master/CONTRIBUTING.md). And you can also go to [Xorm on discourse](https://xorm.discourse.group) to discuss.
|
If you want to pull request, please see [CONTRIBUTING](CONTRIBUTING.md). And you can also go to [Xorm on discourse](https://xorm.discourse.group) to discuss.
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|
|
@ -402,6 +402,9 @@ func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||||
// ModifyColumnSQL returns a SQL to modify SQL
|
// ModifyColumnSQL returns a SQL to modify SQL
|
||||||
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||||
s, _ := ColumnString(db.dialect, col, false, true)
|
s, _ := ColumnString(db.dialect, col, false, true)
|
||||||
|
if col.IsAutoIncrement {
|
||||||
|
s += " " + db.AutoIncrStr()
|
||||||
|
}
|
||||||
if col.Comment != "" {
|
if col.Comment != "" {
|
||||||
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -751,3 +751,43 @@ func getKeysFromMap(m map[string]*schemas.Index) []string {
|
||||||
}
|
}
|
||||||
return ss
|
return ss
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type SyncTestUser struct {
|
||||||
|
Id int64 `xorm:"pk autoincr 'id' comment('primary key 1')"`
|
||||||
|
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SyncTestUser) TableName() string {
|
||||||
|
return "sync_test_user"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type SyncTestUser2 struct {
|
||||||
|
Id int64 `xorm:"pk autoincr 'id' comment('primary key 2')"`
|
||||||
|
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SyncTestUser2) TableName() string {
|
||||||
|
return "sync_test_user"
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSync2_3(t *testing.T) {
|
||||||
|
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
assertSync(t, new(SyncTestUser))
|
||||||
|
|
||||||
|
assert.NoError(t, testEngine.Sync2(new(SyncTestUser2)))
|
||||||
|
tables, err := testEngine.DBMetas()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
tableInfo, err := testEngine.TableInfo(new(SyncTestUser2))
|
||||||
|
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").IsAutoIncrement, tableInfo.GetColumn("id").IsAutoIncrement)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").Name, tableInfo.GetColumn("id").Name)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").SQLType.Name, tableInfo.GetColumn("id").SQLType.Name)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").Nullable, tableInfo.GetColumn("id").Nullable)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").Comment, tableInfo.GetColumn("id").Comment)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue