Merge 3b699fdf3e6cebd6fdb4539438e96b93e59a5bb9 into 89a726ce5da26da893dd3c2d8475e1d66677fd9c

This commit is contained in:
Maxim Lanin 2018-02-09 14:59:20 +00:00 committed by GitHub
commit 2a106b7960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -568,6 +568,13 @@ func (s *DB) AutoMigrate(values ...interface{}) *DB {
return db
}
// AddColumn add column with type
func (s *DB) AddColumn(column string, typ string) *DB {
scope := s.clone().NewScope(s.Value)
scope.addColumn(column, typ)
return scope.db
}
// ModifyColumn modify column to type
func (s *DB) ModifyColumn(column string, typ string) *DB {
scope := s.clone().NewScope(s.Value)

View File

@ -1138,6 +1138,10 @@ func (scope *Scope) dropTable() *Scope {
return scope
}
func (scope *Scope) addColumn(column string, typ string) {
scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v", scope.QuotedTableName(), scope.Quote(column), typ)).Exec()
}
func (scope *Scope) modifyColumn(column string, typ string) {
scope.db.AddError(scope.Dialect().ModifyColumn(scope.QuotedTableName(), scope.Quote(column), typ))
}