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

Method CreateWorkspace

internal/store/workspaces.go:100–121  ·  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

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