Exemplo n.º 1
0
func Update20150807() error {
	key := "20150807"
	// sync new models
	if err := vars.Db.Sync(new(model.Page), new(model.Comment)); err != nil {
		return err
	}
	log.Debug("%s| %-8s | %s,%s", key, "SyncDb",
		reflect.TypeOf(new(model.Page)).String(),
		reflect.TypeOf(new(model.Comment)).String(),
	)
	return nil
}
Exemplo n.º 2
0
// upgrade action
func UpgradeAction(cfg *model.Config) {
	t := time.Now()
	log.Debug("Upgrade | %-8s | %s(%s) -> %s(%s)", "Upgrade", cfg.Version, cfg.Date, vars.VERSION, vars.VERSION_DATE)

	opt := &PrepareOption{true, true, false}
	pre, err := Prepare(opt)
	if err != nil {
		log.Error("Upgrade | %-8s | %s", "Prepare", err.Error())
		return
	}
	log.Info("Upgrade | %-8s | %s", "Prepare", opt.String())

	oldVersion, _ := strconv.Atoi(pre.Config.Date)
	scriptIndex := []int{}
	for vr, _ := range upg.Script {
		if vr > oldVersion {
			scriptIndex = append(scriptIndex, vr)
		}
	}
	sort.Sort(sort.IntSlice(scriptIndex))

	for _, cv := range scriptIndex {
		log.Debug("Upgrade | %-8s | %d ", "Process", cv)
		if err := upg.Script[cv](); err != nil {
			log.Error("Upgrade | %-8s | %s", "Process", err.Error())
			return
		}
	}

	pre.Config.Version = vars.VERSION
	pre.Config.Date = vars.VERSION_DATE
	if err := model.WriteConfig(pre.Config, vars.CONFIG_FILE); err != nil {
		log.Error("Upgrade | %-8s | SyncFail", "Config")
		return
	}

	log.Info("Upgrade | %-8s | Sync | %s", "Config", vars.CONFIG_FILE)
	log.Info("Upgrade | %-8s | %.1fms", "Done", time.Since(t).Seconds()*1000)
}
Exemplo n.º 3
0
// call api function with param
//
// usage:
//      mapi.Call(mapi.Article.Write,*ArticleForm)
//
func Call(fn Func, param interface{}) *Res {
	name := funcName(fn)
	log.Debug("Action | %-8s | %s", "Call", name)
	return fn(param)
}