MCPcopy
hub / github.com/go-gorm/gorm / AddColumn

Method AddColumn

migrator/migrator.go:374–394  ·  view source on GitHub ↗

AddColumn create `name` column for value

(value interface{}, name string)

Source from the content-addressed store, hash-verified

372
373// AddColumn create `name` column for value
374func (m Migrator) AddColumn(value interface{}, name string) error {
375 return m.RunWithValue(value, func(stmt *gorm.Statement) error {
376 // avoid using the same name field
377 if stmt.Schema == nil {
378 return errors.New("failed to get schema")
379 }
380 f := stmt.Schema.LookUpField(name)
381 if f == nil {
382 return fmt.Errorf("failed to look up field with name: %s", name)
383 }
384
385 if !f.IgnoreMigration {
386 return m.DB.Exec(
387 "ALTER TABLE ? ADD ? ?",
388 m.CurrentTable(stmt), clause.Column{Name: f.DBName}, m.DB.Migrator().FullDataTypeOf(f),
389 ).Error
390 }
391
392 return nil
393 })
394}
395
396// DropColumn drop value's `name` column
397func (m Migrator) DropColumn(value interface{}, name string) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 7

RunWithValueMethod · 0.95
CurrentTableMethod · 0.95
LookUpFieldMethod · 0.80
NewMethod · 0.65
ExecMethod · 0.65
FullDataTypeOfMethod · 0.65
MigratorMethod · 0.65

Tested by

no test coverage detected