MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / CreateWorkspace

Method CreateWorkspace

internal/store/workspaces.go:102–123  ·  view source on GitHub ↗

CreateWorkspace mints a workspace against the pool. Callers already inside a transaction want createWorkspaceQ instead. With WithPlanLimit() the mint runs in its own transaction and is refused with a *PlanLimitError when the owner is already at their workspaces limit, counted under the owner lock (

(input models.WorkspaceCreate, opts ...MintOption)

Source from the content-addressed store, hash-verified

100// the import asking for the owner lock at its end. With one order, the create
101// waits on the slug holding nothing, and the import commits.
102func (s *Store) CreateWorkspace(input models.WorkspaceCreate, opts ...MintOption) (*models.Workspace, error) {
103 mo := resolveMintOptions(opts)
104 if !mo.planLimit {
105 return s.createWorkspaceQ(s.db, input, mo.preserveSlug)
106 }
107 tx, err := s.db.Begin()
108 if err != nil {
109 return nil, fmt.Errorf("create workspace: begin: %w", err)
110 }
111 defer tx.Rollback()
112 ws, err := s.createWorkspaceQ(tx, input, mo.preserveSlug)
113 if err != nil {
114 return nil, err
115 }
116 if err := s.enforceUserLimitTx(tx, input.OwnerID, "workspaces", 1); err != nil {
117 return nil, err
118 }
119 if err := tx.Commit(); err != nil {
120 return nil, fmt.Errorf("create workspace: commit: %w", err)
121 }
122 return ws, nil
123}
124
125// workspaceSlugProbedHook, when set by a test, runs between the slug probe and
126// the INSERT: the gap a concurrent create of the same name lands in (BUG-3307).

Calls 6

createWorkspaceQMethod · 0.95
enforceUserLimitTxMethod · 0.95
resolveMintOptionsFunction · 0.85
BeginMethod · 0.80
RollbackMethod · 0.80
CommitMethod · 0.45