added switch to manually migrate data
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Paul 2023-11-10 23:24:23 +01:00
parent 246406f638
commit 8deaf69baf

View File

@ -44,27 +44,29 @@ func Initialize(ctx *context.Context, cfg *config.Config) (err error) {
log.Println("Syncing tables")
err = models.NewEngine(ctx, cfg)
migrate(cfg)
if cfg.Switchs.Migrate {
migrate(cfg)
}
return
}
func migrate(cfg *config.Config) (err error) {
var a []models.CfgSet
num, err := cfg.Db.FindAndCount(&a)
var cfgsets []models.CfgSet
num, err := cfg.Db.FindAndCount(&cfgsets)
fmt.Printf("%d sets found\n", num)
if err != nil {
fmt.Println(err)
}
for _, i := range a {
var r = i.Regex
r = strings.Trim(r, "()")
rs := strings.Split(r, "|")
for _, cfgset := range cfgsets {
var reg = cfgset.Regex
reg = strings.Trim(reg, "()")
rs := strings.Split(reg, "|")
for _, v := range rs {
if v != "" {
n := models.CfgExpr{
Expr: v,
Set: &i,
Set: &cfgset,
}
cfg.Db.Insert(&n)
}