Apply dbconn explicit to all conns by default

This commit is contained in:
lash 2025-01-24 10:09:46 +00:00
parent 15ce29a1a4
commit 03d19283f6
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 22 additions and 15 deletions

View File

@ -26,13 +26,13 @@ var (
)
type Override struct {
DbConn *string
DbConn string
DbConnMode storage.DbMode
StateConn *string
StateConn string
StateConnMode storage.DbMode
ResourceConn *string
ResourceConn string
ResourceConnMode storage.DbMode
UserConn *string
UserConn string
UserConnMode storage.DbMode
}
@ -63,18 +63,21 @@ func setConn() error {
}
func ApplyConn(override *Override) {
if override.DbConn != nil {
dbConn = *override.DbConn
if override.DbConn != "?" {
dbConn = override.DbConn
stateDbConn = override.StateConn
resourceDbConn = override.ResourceConn
userDbConn = override.UserConn
}
dbConnMode = override.DbConnMode
if override.StateConn != nil {
stateDbConn = *override.StateConn
if override.StateConn != "?" {
stateDbConn = override.StateConn
}
if override.ResourceConn != nil {
resourceDbConn = *override.ResourceConn
if override.ResourceConn != "?" {
resourceDbConn = override.ResourceConn
}
if override.UserConn != nil {
userDbConn = *override.UserConn
if override.UserConn != "?" {
userDbConn = override.UserConn
}
if dbConn == "?" {
@ -94,6 +97,10 @@ func ApplyConn(override *Override) {
userDbConnMode = dbConnMode
}
logg.Debugf("conns", "conn", dbConn, "user", userDbConn)
if override.DbConnMode != storage.DBMODE_ANY {
dbConnMode = override.DbConnMode
}
if override.StateConnMode != storage.DBMODE_ANY {
stateDbConnMode = override.StateConnMode
}

View File

@ -169,7 +169,9 @@ func ensureSchemaExists(ctx context.Context, conn ConnData) error {
func applySession(ctx context.Context, store db.Db) error {
sessionId, ok := ctx.Value("SessionId").(string)
if !ok {
return fmt.Errorf("missing session to apply to store: %v", store)
logg.DebugCtxf(ctx, "missing session to apply", "store", store)
return nil
//return fmt.Errorf("missing session to apply to store: %v", store)
}
store.SetSession(sessionId)
return nil
@ -184,7 +186,6 @@ func (ms *MenuStorageService) GetPersister(ctx context.Context) (*persist.Persis
if err != nil {
return nil, err
}
pr := persist.NewPersister(stateStore)
logg.TraceCtxf(ctx, "menu storage service", "persist", pr, "store", stateStore)
return pr, nil
@ -195,7 +196,6 @@ func (ms *MenuStorageService) GetUserdataDb(ctx context.Context) (db.Db, error)
if err != nil {
return nil, err
}
err = applySession(ctx, userStore)
if err != nil {
return nil, err