From fcacfc08e3c8d8da9cb307d77e3a60bb34d1b415 Mon Sep 17 00:00:00 2001 From: Priyesh <43954392+priyesh-lb@users.noreply.github.com> Date: Fri, 17 May 2019 16:19:26 +0530 Subject: [PATCH] Beego skipping some migrations Beego skipping some migrations #3657 --- migration/migration.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/migration/migration.go b/migration/migration.go index 97e10c2e..5ddfd972 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -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 +}