-
Notifications
You must be signed in to change notification settings - Fork 159
/
migration_v24.go
44 lines (36 loc) · 1.13 KB
/
migration_v24.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package db
import (
"fmt"
"github.com/openziti/storage/ast"
"github.com/openziti/storage/boltz"
)
func (m *Migrations) addIdentityIdToSessions(step *boltz.MigrationStep) {
cursor := m.stores.Session.IterateIds(step.Ctx.Tx(), ast.BoolNodeTrue)
fieldChecker := boltz.MapFieldChecker{
FieldSessionIdentity: struct{}{},
}
for cursor.IsValid() {
sessionId := string(cursor.Current())
session, err := m.stores.Session.LoadOneById(step.Ctx.Tx(), sessionId)
if err != nil {
step.SetError(fmt.Errorf("could no load session by id [%s]: %v", sessionId, err))
return
}
if session == nil {
step.SetError(fmt.Errorf("session [%s] load did not error but session is null", sessionId))
return
}
if session.IdentityId == "" {
if apiSession, err := m.stores.ApiSession.LoadOneById(step.Ctx.Tx(), session.ApiSessionId); err == nil {
if apiSession != nil {
session.IdentityId = apiSession.IdentityId
if err = m.stores.Session.Update(step.Ctx, session, fieldChecker); err != nil {
step.SetError(fmt.Errorf("could not update session [%s]: %v", session.Id, err))
return
}
}
}
}
cursor.Next()
}
}