added switch to manually migrate data
This commit is contained in:
parent
246406f638
commit
8deaf69baf
@ -44,27 +44,29 @@ func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
|
|||||||
log.Println("Syncing tables")
|
log.Println("Syncing tables")
|
||||||
err = models.NewEngine(ctx, cfg)
|
err = models.NewEngine(ctx, cfg)
|
||||||
|
|
||||||
|
if cfg.Switchs.Migrate {
|
||||||
migrate(cfg)
|
migrate(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrate(cfg *config.Config) (err error) {
|
func migrate(cfg *config.Config) (err error) {
|
||||||
var a []models.CfgSet
|
var cfgsets []models.CfgSet
|
||||||
num, err := cfg.Db.FindAndCount(&a)
|
num, err := cfg.Db.FindAndCount(&cfgsets)
|
||||||
fmt.Printf("%d sets found\n", num)
|
fmt.Printf("%d sets found\n", num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
for _, i := range a {
|
for _, cfgset := range cfgsets {
|
||||||
var r = i.Regex
|
var reg = cfgset.Regex
|
||||||
r = strings.Trim(r, "()")
|
reg = strings.Trim(reg, "()")
|
||||||
rs := strings.Split(r, "|")
|
rs := strings.Split(reg, "|")
|
||||||
for _, v := range rs {
|
for _, v := range rs {
|
||||||
if v != "" {
|
if v != "" {
|
||||||
n := models.CfgExpr{
|
n := models.CfgExpr{
|
||||||
Expr: v,
|
Expr: v,
|
||||||
Set: &i,
|
Set: &cfgset,
|
||||||
}
|
}
|
||||||
cfg.Db.Insert(&n)
|
cfg.Db.Insert(&n)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user