mirror of
https://github.com/openziti/ziti.git
synced 2026-10-15 08:31:50 +00:00
Merge pull request #543 from openziti/add.api.session.clearing.migration
add migration to remove api sessions/sessions on migration from 18->19
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/foundation/storage/ast"
|
||||
"github.com/openziti/foundation/storage/boltz"
|
||||
)
|
||||
|
||||
//Removes all ApiSession and Session from the edge. Necessary from 0.18 -> 0.19
|
||||
//as the id format changed and API Session sync'ing depends on monotonic ids.
|
||||
func (m *Migrations) removeAllSessions(step *boltz.MigrationStep) {
|
||||
for cursor := m.stores.Session.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() {
|
||||
current := cursor.Current()
|
||||
currentSessionId := string(current)
|
||||
|
||||
if err := m.stores.Session.DeleteById(step.Ctx, currentSessionId); err != nil {
|
||||
step.SetError(fmt.Errorf("error cleaing up sessions for migration: %v", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for cursor := m.stores.ApiSession.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue); cursor.IsValid(); cursor.Next() {
|
||||
current := cursor.Current()
|
||||
currentApiSessionId := string(current)
|
||||
|
||||
if err := m.stores.ApiSession.DeleteById(step.Ctx, currentApiSessionId); err != nil {
|
||||
step.SetError(fmt.Errorf("error cleaing up api sessions for migration: %v", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CurrentDbVersion = 16
|
||||
CurrentDbVersion = 17
|
||||
FieldVersion = "version"
|
||||
)
|
||||
|
||||
@@ -124,6 +124,10 @@ func (m *Migrations) migrate(step *boltz.MigrationStep) int {
|
||||
m.removeOrphanedOttCaEnrollments(step)
|
||||
}
|
||||
|
||||
if step.CurrentVersion < 17 {
|
||||
m.removeAllSessions(step)
|
||||
}
|
||||
|
||||
// current version
|
||||
if step.CurrentVersion <= CurrentDbVersion {
|
||||
return CurrentDbVersion
|
||||
|
||||
Reference in New Issue
Block a user