diff --git a/main.go b/main.go index b23ae2f2..9172a9bc 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/scope.go b/scope.go index a10cb3a2..60ffe8dd 100644 --- a/scope.go +++ b/scope.go @@ -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)) }