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

Function TestMigrateTable

tests/migrate_test.go:423–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

421}
422
423func TestMigrateTable(t *testing.T) {
424 type TableStruct struct {
425 gorm.Model
426 Name string
427 }
428
429 DB.Migrator().DropTable(&TableStruct{})
430 DB.AutoMigrate(&TableStruct{})
431
432 if !DB.Migrator().HasTable(&TableStruct{}) {
433 t.Fatalf("should found created table")
434 }
435
436 type NewTableStruct struct {
437 gorm.Model
438 Name string
439 }
440
441 if err := DB.Migrator().RenameTable(&TableStruct{}, &NewTableStruct{}); err != nil {
442 t.Fatalf("Failed to rename table, got error %v", err)
443 }
444
445 if !DB.Migrator().HasTable("new_table_structs") {
446 t.Fatal("should found renamed table")
447 }
448
449 DB.Migrator().DropTable("new_table_structs")
450
451 if DB.Migrator().HasTable(&NewTableStruct{}) {
452 t.Fatal("should not found dropped table")
453 }
454}
455
456func TestMigrateWithQuotedIndex(t *testing.T) {
457 if DB.Dialector.Name() != "mysql" {

Callers

nothing calls this directly

Calls 5

DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65
HasTableMethod · 0.65
RenameTableMethod · 0.65

Tested by

no test coverage detected