1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-25 05:20:49 +00:00

Beego skipping some migrations

Beego skipping some migrations #3657
This commit is contained in:
Priyesh 2019-05-17 16:19:26 +05:30 committed by GitHub
parent 58b2ac702c
commit fcacfc08e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -176,8 +176,9 @@ func Register(name string, m Migrationer) error {
func Upgrade(lasttime int64) error {
sm := sortMap(migrationMap)
i := 0
migs, _ := getAllMigrations()
for _, v := range sm {
if v.created > lasttime {
if _, ok := migs[v.name]; !ok {
logs.Info("start upgrade", v.name)
v.m.Reset()
v.m.Up()
@ -310,3 +311,20 @@ func isRollBack(name string) bool {
}
return false
}
func getAllMigrations() (map[string]string, error) {
o := orm.NewOrm()
var maps []orm.Params
migs := make(map[string]string)
num, err := o.Raw("select * from migrations order by id_migration desc").Values(&maps)
if err != nil {
logs.Info("get name has error", err)
return migs, err
}
if num > 0 {
for _, v := range maps {
name := v["name"].(string)
migs[name] = v["status"].(string)
}
}
return migs, nil
}