From 5ec44c3d3e5c99175bb8e8c36a20e47d70c6ea54 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Fri, 19 Feb 2021 09:54:55 -0500 Subject: [PATCH] add migration to remove api sessions/sessions on migration from 18->19 --- controller/persistence/migration_v17.go | 31 +++++++++++++++++++++++++ controller/persistence/migrations.go | 6 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 controller/persistence/migration_v17.go diff --git a/controller/persistence/migration_v17.go b/controller/persistence/migration_v17.go new file mode 100644 index 000000000..2d78f62b8 --- /dev/null +++ b/controller/persistence/migration_v17.go @@ -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 + } + } +} diff --git a/controller/persistence/migrations.go b/controller/persistence/migrations.go index e72188770..3c51bf5ad 100644 --- a/controller/persistence/migrations.go +++ b/controller/persistence/migrations.go @@ -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