MCPcopy Create free account
hub / github.com/bytebase/bytebase / UpdateWorkspace

Method UpdateWorkspace

backend/store/workspace.go:214–231  ·  view source on GitHub ↗

UpdateWorkspace updates workspace payload fields atomically using jsonb_set. Each field is updated independently in SQL to avoid lost-update races.

(ctx context.Context, patch *UpdateWorkspaceMessage)

Source from the content-addressed store, hash-verified

212// UpdateWorkspace updates workspace payload fields atomically using jsonb_set.
213// Each field is updated independently in SQL to avoid lost-update races.
214func (s *Store) UpdateWorkspace(ctx context.Context, patch *UpdateWorkspaceMessage) error {
215 q := qb.Q().Space("UPDATE workspace SET payload = payload")
216 if v := patch.Title; v != nil {
217 q.Space("|| jsonb_build_object('title', ?::text)", *v)
218 }
219 if v := patch.Logo; v != nil {
220 q.Space("|| jsonb_build_object('logo', ?::text)", *v)
221 }
222 q.Space("WHERE resource_id = ? AND deleted = FALSE", patch.ResourceID)
223 query, args, err := q.ToSQL()
224 if err != nil {
225 return errors.Wrapf(err, "failed to build sql")
226 }
227 if _, err := s.GetDB().ExecContext(ctx, query, args...); err != nil {
228 return errors.Wrapf(err, "failed to update workspace")
229 }
230 return nil
231}
232
233// DeleteWorkspace soft-deletes a workspace by setting deleted = TRUE.
234func (s *Store) DeleteWorkspace(ctx context.Context, resourceID string) error {

Callers

nothing calls this directly

Calls 4

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80

Tested by

no test coverage detected