mysql alter column comment ready.

This commit is contained in:
brookechen 2023-07-11 17:18:36 +08:00
parent 604489eb38
commit a019b1ea33
3 changed files with 6 additions and 3 deletions

View File

@ -397,6 +397,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.Comment != "" {
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
}
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s) return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
} }

View File

@ -311,7 +311,7 @@ func TestColumnCommentUpdate(t *testing.T) {
assert.NoError(t, testEngine.Sync2(new(TestCommentUpdate2))) // modify table column comment assert.NoError(t, testEngine.Sync2(new(TestCommentUpdate2))) // modify table column comment
switch testEngine.Dialect().URI().DBType { 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: default:
t.Skip() t.Skip()
return return

View File

@ -181,8 +181,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
} }
} }
} else if col.Comment != oriCol.Comment { } 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)) _, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
} }
} }