Is it possible to automigrate all structs automatically?
Currently it seems like the name of each struct to migrate needs to be passed to this function https://github.com/jinzhu/gorm/blob/690cb1430c2e27011324c51826301a7daf728e65/main.go#L261
Because gorm can't know which struct you want to migrate, so can't do this automatically.
But I am doing something like this in my application.
package main
import (
"fmt"
. "xxx.com/xxxx/xxxx/app/models"
. "xxx.com/xxxx/xxxx/db"
"reflect"
)
func main() {
for _, model := range []interface{}{
Payment{}, Invoice{}, Transaction{},
SubscriptionService{}, SubscriptionBenefit{}, Subscription{},
Address{}, User{}, UserService{},
Service{},
} {
if err := DB.AutoMigrate(model).Error; err != nil {
fmt.Println(err)
} else {
fmt.Println("Auto migrating", reflect.TypeOf(model).Name(), "...")
}
}
}
Thanks for the tip!
On Thu, Jan 2, 2014 at 1:49 PM, Jinzhu [email protected] wrote:
Closed #38 https://github.com/jinzhu/gorm/issues/38.
—
Reply to this email directly or view it on GitHubhttps://github.com/jinzhu/gorm/issues/38
.
Now, do you have a new method to solve it ?
Thanks. @jinzhu
Most helpful comment
Because gorm can't know which struct you want to migrate, so can't do this automatically.
But I am doing something like this in my application.