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

Function RunMigrations

tests/tests_test.go:120–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118}
119
120func RunMigrations() {
121 var err error
122 allModels := []interface{}{&User{}, &Account{}, &Pet{}, &Company{}, &Toy{}, &Language{}, &Coupon{}, &CouponProduct{}, &Order{}, &Parent{}, &Child{}, &Tools{}}
123 rand.Seed(time.Now().UnixNano())
124 rand.Shuffle(len(allModels), func(i, j int) { allModels[i], allModels[j] = allModels[j], allModels[i] })
125
126 DB.Migrator().DropTable("user_friends", "user_speaks")
127
128 if err = DB.Migrator().DropTable(allModels...); err != nil {
129 log.Printf("Failed to drop table, got error %v\n", err)
130 os.Exit(1)
131 }
132
133 if err = DB.AutoMigrate(allModels...); err != nil {
134 log.Printf("Failed to auto migrate, but got error %v\n", err)
135 os.Exit(1)
136 }
137
138 for _, m := range allModels {
139 if !DB.Migrator().HasTable(m) {
140 log.Printf("Failed to create table for %#v\n", m)
141 os.Exit(1)
142 }
143 }
144}

Callers 1

initFunction · 0.85

Calls 5

PrintfMethod · 0.80
DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65
HasTableMethod · 0.65

Tested by

no test coverage detected