diff --git a/controller/db/migration.go b/controller/db/migration.go index be6ecf074..d10b091d8 100644 --- a/controller/db/migration.go +++ b/controller/db/migration.go @@ -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"