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

Method RenameColumn

migrator/migrator.go:450–467  ·  view source on GitHub ↗

RenameColumn rename value's field name from oldName to newName

(value interface{}, oldName, newName string)

Source from the content-addressed store, hash-verified

448
449// RenameColumn rename value's field name from oldName to newName
450func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error {
451 return m.RunWithValue(value, func(stmt *gorm.Statement) error {
452 if stmt.Schema != nil {
453 if field := stmt.Schema.LookUpField(oldName); field != nil {
454 oldName = field.DBName
455 }
456
457 if field := stmt.Schema.LookUpField(newName); field != nil {
458 newName = field.DBName
459 }
460 }
461
462 return m.DB.Exec(
463 "ALTER TABLE ? RENAME COLUMN ? TO ?",
464 m.CurrentTable(stmt), clause.Column{Name: oldName}, clause.Column{Name: newName},
465 ).Error
466 })
467}
468
469// MigrateColumn migrate column
470func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 4

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

Tested by

no test coverage detected