chore: tweak workspace setting definition

This commit is contained in:
johnnyjoy
2024-08-17 21:06:42 +08:00
parent c98e717f5b
commit f5edcff24b
12 changed files with 242 additions and 231 deletions

View File

@ -12,36 +12,26 @@ func (s *Store) MigrateWorkspaceSettings(ctx context.Context) error {
return err
}
workspaceSettingGeneral, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
})
workspaceGeneralSetting, err := s.GetWorkspaceGeneralSetting(ctx)
if err != nil {
return err
}
if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil {
workspaceSettingGeneral = &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{
General: &storepb.WorkspaceSetting_GeneralSetting{},
},
}
}
updateWorkspaceSetting := false
for _, workspaceSetting := range workspaceSettings {
if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY {
workspaceSettingGeneral.GetGeneral().LicenseKey = workspaceSetting.Raw
workspaceGeneralSetting.LicenseKey = workspaceSetting.Raw
updateWorkspaceSetting = true
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_LICENSE_KEY); err != nil {
return err
}
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE {
workspaceSettingGeneral.GetGeneral().CustomStyle = workspaceSetting.Raw
workspaceGeneralSetting.CustomStyle = workspaceSetting.Raw
updateWorkspaceSetting = true
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_CUSTOM_STYLE); err != nil {
return err
}
} else if workspaceSetting.Key == storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION {
workspaceSettingGeneral.GetGeneral().SecretSession = workspaceSetting.Raw
workspaceGeneralSetting.SecretSession = workspaceSetting.Raw
updateWorkspaceSetting = true
if err := s.DeleteWorkspaceSetting(ctx, storepb.WorkspaceSettingKey_WORKSPACE_SETTING_SECRET_SESSION); err != nil {
return err
@ -49,7 +39,12 @@ func (s *Store) MigrateWorkspaceSettings(ctx context.Context) error {
}
}
if updateWorkspaceSetting {
if _, err := s.UpsertWorkspaceSetting(ctx, workspaceSettingGeneral); err != nil {
if _, err := s.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
Value: &storepb.WorkspaceSetting_General{
General: workspaceGeneralSetting,
},
}); err != nil {
return err
}
}