RenameColumn rename value's field name from oldName to newName
(value interface{}, oldName, newName string)
| 448 | |
| 449 | // RenameColumn rename value's field name from oldName to newName |
| 450 | func (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 |
| 470 | func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error { |
nothing calls this directly
no test coverage detected