Merge pull request openziti/fabric#108 from openziti/fix-name-indices

Fix name indices
This commit is contained in:
Paul Lorenz
2020-08-03 23:37:59 -04:00
committed by GitHub
+19 -2
View File
@@ -5,11 +5,12 @@ import (
"github.com/openziti/foundation/storage/ast"
"github.com/openziti/foundation/storage/boltz"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"strings"
"time"
)
const CurrentDbVersion = 3
const CurrentDbVersion = 4
func (stores *stores) migrate(step *boltz.MigrationStep) int {
if step.CurrentVersion > CurrentDbVersion {
@@ -30,6 +31,10 @@ func (stores *stores) migrate(step *boltz.MigrationStep) int {
stores.setNames(step, stores.router)
}
if step.CurrentVersion < 4 {
stores.fixNameIndexes(step)
}
if step.CurrentVersion <= CurrentDbVersion {
return CurrentDbVersion
}
@@ -71,12 +76,24 @@ func (stores *stores) setNames(step *boltz.MigrationStep, store boltz.CrudStore)
return
}
if name := entityBucket.GetString(FieldName); name == nil || len(*name) == 0 {
entityBucket.SetString(FieldName, string(id), nil)
entityBucket.SetString(FieldName, id, nil)
step.SetError(entityBucket.GetError())
}
}
}
func (stores *stores) fixNameIndexes(step *boltz.MigrationStep) {
c := stores.service.indexName.(boltz.Constraint)
step.SetError(c.CheckIntegrity(step.Ctx.Tx(), true, func(err error, fixed bool) {
log.WithError(err).Debugf("Fixing service name index. Fixed? %v", fixed)
}))
c = stores.router.indexName.(boltz.Constraint)
step.SetError(c.CheckIntegrity(step.Ctx.Tx(), true, func(err error, fixed bool) {
log.WithError(err).Debugf("Fixing router name index. Fixed? %v", fixed)
}))
}
const (
FieldServiceEgress = "egress"
FieldServiceBinding = "binding"