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

Method AlterColumn

migrator/migrator.go:412–426  ·  view source on GitHub ↗

AlterColumn alter value's `field` column's type based on schema definition

(value interface{}, field string)

Source from the content-addressed store, hash-verified

410
411// AlterColumn alter value's `field` column's type based on schema definition
412func (m Migrator) AlterColumn(value interface{}, field string) error {
413 return m.RunWithValue(value, func(stmt *gorm.Statement) error {
414 if stmt.Schema != nil {
415 if field := stmt.Schema.LookUpField(field); field != nil {
416 fieldType := m.FullDataTypeOf(field)
417 return m.DB.Exec(
418 "ALTER TABLE ? ALTER COLUMN ? TYPE ?",
419 m.CurrentTable(stmt), clause.Column{Name: field.DBName}, fieldType,
420 ).Error
421
422 }
423 }
424 return fmt.Errorf("failed to look up field with name: %s", field)
425 })
426}
427
428// HasColumn check has column `field` for value or not
429func (m Migrator) HasColumn(value interface{}, field string) bool {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 5

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

Tested by

no test coverage detected