RenameTable rename table from oldName to newName
(oldName, newName interface{})
| 344 | |
| 345 | // RenameTable rename table from oldName to newName |
| 346 | func (m Migrator) RenameTable(oldName, newName interface{}) error { |
| 347 | var oldTable, newTable interface{} |
| 348 | if v, ok := oldName.(string); ok { |
| 349 | oldTable = clause.Table{Name: v} |
| 350 | } else { |
| 351 | stmt := &gorm.Statement{DB: m.DB} |
| 352 | if err := stmt.Parse(oldName); err == nil { |
| 353 | oldTable = m.CurrentTable(stmt) |
| 354 | } else { |
| 355 | return err |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if v, ok := newName.(string); ok { |
| 360 | newTable = clause.Table{Name: v} |
| 361 | } else { |
| 362 | stmt := &gorm.Statement{DB: m.DB} |
| 363 | if err := stmt.Parse(newName); err == nil { |
| 364 | newTable = m.CurrentTable(stmt) |
| 365 | } else { |
| 366 | return err |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return m.DB.Exec("ALTER TABLE ? RENAME TO ?", oldTable, newTable).Error |
| 371 | } |
| 372 | |
| 373 | // AddColumn create `name` column for value |
| 374 | func (m Migrator) AddColumn(value interface{}, name string) error { |
nothing calls this directly
no test coverage detected