add column comment for postgres

This commit is contained in:
fanybook 2021-11-04 14:32:55 +08:00
parent 5feff03a17
commit 6fb5873890
1 changed files with 21 additions and 0 deletions

View File

@ -351,9 +351,30 @@ func (session *Session) Sync(beans ...interface{}) error {
if err = session.addColumn(col.Name); err != nil {
return err
}
// add column comment for postgres
if col.Comment != "" && engine.Dialect().URI().DBType == schemas.POSTGRES {
// @see: integrations/engine_test.go#TestGetColumns
addColumnCommentSql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS '%s'", session.engine.Quote(tbNameWithSchema), session.engine.Quote(col.Name), col.Comment)
_, err = session.Exec(addColumnCommentSql)
if err != nil {
return err
}
}
continue
}
// add column comment for postgres
if col.Comment != "" && engine.Dialect().URI().DBType == schemas.POSTGRES {
// @see: integrations/engine_test.go#TestGetColumns
addColumnCommentSql := fmt.Sprintf("COMMENT ON COLUMN %s.%s IS '%s'", session.engine.Quote(tbNameWithSchema), session.engine.Quote(col.Name), col.Comment)
_, err = session.Exec(addColumnCommentSql)
if err != nil {
return err
}
}
err = nil
expectedType := engine.dialect.SQLType(col)
curType := engine.dialect.SQLType(oriCol)