mirror of
https://github.com/astaxie/beego.git
synced 2024-11-24 15:00:55 +00:00
parent
58b2ac702c
commit
fcacfc08e3
@ -176,8 +176,9 @@ func Register(name string, m Migrationer) error {
|
|||||||
func Upgrade(lasttime int64) error {
|
func Upgrade(lasttime int64) error {
|
||||||
sm := sortMap(migrationMap)
|
sm := sortMap(migrationMap)
|
||||||
i := 0
|
i := 0
|
||||||
|
migs, _ := getAllMigrations()
|
||||||
for _, v := range sm {
|
for _, v := range sm {
|
||||||
if v.created > lasttime {
|
if _, ok := migs[v.name]; !ok {
|
||||||
logs.Info("start upgrade", v.name)
|
logs.Info("start upgrade", v.name)
|
||||||
v.m.Reset()
|
v.m.Reset()
|
||||||
v.m.Up()
|
v.m.Up()
|
||||||
@ -310,3 +311,20 @@ func isRollBack(name string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user