mysql alter column comment ready.
This commit is contained in:
parent
604489eb38
commit
a019b1ea33
|
@ -397,6 +397,9 @@ func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
|||
// ModifyColumnSQL returns a SQL to modify SQL
|
||||
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
s, _ := ColumnString(db.dialect, col, false, true)
|
||||
if col.Comment != "" {
|
||||
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
||||
}
|
||||
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ func TestColumnCommentUpdate(t *testing.T) {
|
|||
assert.NoError(t, testEngine.Sync2(new(TestCommentUpdate2))) // modify table column comment
|
||||
|
||||
switch testEngine.Dialect().URI().DBType {
|
||||
case schemas.POSTGRES: // only postgres dialect implement the feature of modify comment in postgres.ModifyColumnSQL
|
||||
case schemas.POSTGRES, schemas.MYSQL: // only postgres / mysql dialect implement the feature of modify comment in postgres.ModifyColumnSQL
|
||||
default:
|
||||
t.Skip()
|
||||
return
|
||||
|
|
4
sync.go
4
sync.go
|
@ -181,8 +181,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
|||
}
|
||||
}
|
||||
} else if col.Comment != oriCol.Comment {
|
||||
// only postgres dialect implement update comment now.
|
||||
if engine.dialect.URI().DBType == schemas.POSTGRES {
|
||||
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
||||
engine.dialect.URI().DBType == schemas.MYSQL {
|
||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue