fix: #2444
This commit is contained in:
parent
589acfff86
commit
ebbe5b71b6
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,7 @@ func TestSyncTable(t *testing.T) {
|
||||||
tableInfo, err = testEngine.TableInfo(new(SyncTable3))
|
tableInfo, err = testEngine.TableInfo(new(SyncTable3))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tables[0].GetColumn("name")), testEngine.Dialect().SQLType(tableInfo.GetColumn("name")))
|
assert.EqualValues(t, testEngine.Dialect().SQLType(tables[0].GetColumn("name")), testEngine.Dialect().SQLType(tableInfo.GetColumn("name")))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncTable2(t *testing.T) {
|
func TestSyncTable2(t *testing.T) {
|
||||||
|
@ -396,6 +397,7 @@ func TestIndexAndUnique(t *testing.T) {
|
||||||
assert.NoError(t, testEngine.DropIndexes(&IndexOrUnique{}))
|
assert.NoError(t, testEngine.DropIndexes(&IndexOrUnique{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestMetaInfo(t *testing.T) {
|
func TestMetaInfo(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
assert.NoError(t, testEngine.Sync(new(CustomTableName), new(IndexOrUnique)))
|
assert.NoError(t, testEngine.Sync(new(CustomTableName), new(IndexOrUnique)))
|
||||||
|
@ -537,8 +539,11 @@ func TestModifyColum(t *testing.T) {
|
||||||
})
|
})
|
||||||
_, err := testEngine.Exec(alterSQL)
|
_, err := testEngine.Exec(alterSQL)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type TestCollateColumn struct {
|
type TestCollateColumn struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 `xorm:"unique(s)"`
|
UserId int64 `xorm:"unique(s)"`
|
||||||
|
@ -751,3 +756,34 @@ func getKeysFromMap(m map[string]*schemas.Index) []string {
|
||||||
}
|
}
|
||||||
return ss
|
return ss
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestSync2_3(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
{
|
||||||
|
type User struct {
|
||||||
|
Id int `xorm:"pk autoincr 'id'"`
|
||||||
|
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, testEngine.Sync2(new(User)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// add comment for id column
|
||||||
|
type User struct {
|
||||||
|
Id int `xorm:"pk autoincr 'id' comment('primary key')"`
|
||||||
|
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, testEngine.Sync2(new(User)))
|
||||||
|
tables, err := testEngine.DBMetas()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
tableInfo, err := testEngine.TableInfo(new(User))
|
||||||
|
|
||||||
|
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, tableInfo.GetColumn("id").SQLType)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").Nullable, tableInfo.GetColumn("id").Nullable)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").Comment, tableInfo.GetColumn("id").Comment)
|
||||||
|
assert.EqualValues(t, tables[0].GetColumn("id").IsPrimaryKey, tableInfo.GetColumn("id").IsPrimaryKey)
|
||||||
|
}
|
Loading…
Reference in New Issue