1919 Alert ,
2020 GetAlertsWithPromptAndOutputRow ,
2121 GetPromptWithOutputsRow ,
22+ GetWorkspaceByNameConditions ,
2223 Output ,
2324 Prompt ,
2425 Session ,
25- Workspace ,
26- WorkspaceActive ,
26+ WorkspaceRow ,
27+ WorkspaceWithSessionInfo ,
2728)
2829from codegate .pipeline .base import PipelineContext
2930
@@ -263,15 +264,17 @@ async def record_context(self, context: Optional[PipelineContext]) -> None:
263264 except Exception as e :
264265 logger .error (f"Failed to record context: { context } ." , error = str (e ))
265266
266- async def add_workspace (self , workspace_name : str ) -> Workspace :
267+ async def add_workspace (self , workspace_name : str ) -> WorkspaceRow :
267268 """Add a new workspace to the DB.
268269
269270 This handles validation and insertion of a new workspace.
270271
271272 It may raise a ValidationError if the workspace name is invalid.
272273 or a AlreadyExistsError if the workspace already exists.
273274 """
274- workspace = Workspace (id = str (uuid .uuid4 ()), name = workspace_name , custom_instructions = None )
275+ workspace = WorkspaceRow (
276+ id = str (uuid .uuid4 ()), name = workspace_name , custom_instructions = None
277+ )
275278 sql = text (
276279 """
277280 INSERT INTO workspaces (id, name)
@@ -289,7 +292,7 @@ async def add_workspace(self, workspace_name: str) -> Workspace:
289292 raise AlreadyExistsError (f"Workspace { workspace_name } already exists." )
290293 return added_workspace
291294
292- async def update_workspace (self , workspace : Workspace ) -> Workspace :
295+ async def update_workspace (self , workspace : WorkspaceRow ) -> WorkspaceRow :
293296 sql = text (
294297 """
295298 UPDATE workspaces SET
@@ -319,7 +322,7 @@ async def update_session(self, session: Session) -> Optional[Session]:
319322 active_session = await self ._execute_update_pydantic_model (session , sql , should_raise = True )
320323 return active_session
321324
322- async def soft_delete_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
325+ async def soft_delete_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
323326 sql = text (
324327 """
325328 UPDATE workspaces
@@ -333,7 +336,7 @@ async def soft_delete_workspace(self, workspace: Workspace) -> Optional[Workspac
333336 )
334337 return deleted_workspace
335338
336- async def hard_delete_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
339+ async def hard_delete_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
337340 sql = text (
338341 """
339342 DELETE FROM workspaces
@@ -346,7 +349,7 @@ async def hard_delete_workspace(self, workspace: Workspace) -> Optional[Workspac
346349 )
347350 return deleted_workspace
348351
349- async def recover_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
352+ async def recover_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
350353 sql = text (
351354 """
352355 UPDATE workspaces
@@ -460,20 +463,20 @@ async def get_alerts_with_prompt_and_output(
460463 )
461464 return prompts
462465
463- async def get_workspaces (self ) -> List [WorkspaceActive ]:
466+ async def get_workspaces (self ) -> List [WorkspaceWithSessionInfo ]:
464467 sql = text (
465468 """
466469 SELECT
467- w.id, w.name, s.active_workspace_id
470+ w.id, w.name, s.id as session_id
468471 FROM workspaces w
469472 LEFT JOIN sessions s ON w.id = s.active_workspace_id
470473 WHERE w.deleted_at IS NULL
471474 """
472475 )
473- workspaces = await self ._execute_select_pydantic_model (WorkspaceActive , sql )
476+ workspaces = await self ._execute_select_pydantic_model (WorkspaceWithSessionInfo , sql )
474477 return workspaces
475478
476- async def get_archived_workspaces (self ) -> List [Workspace ]:
479+ async def get_archived_workspaces (self ) -> List [WorkspaceRow ]:
477480 sql = text (
478481 """
479482 SELECT
@@ -483,10 +486,10 @@ async def get_archived_workspaces(self) -> List[Workspace]:
483486 ORDER BY deleted_at DESC
484487 """
485488 )
486- workspaces = await self ._execute_select_pydantic_model (Workspace , sql )
489+ workspaces = await self ._execute_select_pydantic_model (WorkspaceRow , sql )
487490 return workspaces
488491
489- async def get_workspace_by_name (self , name : str ) -> Optional [Workspace ]:
492+ async def get_workspace_by_name (self , name : str ) -> Optional [WorkspaceRow ]:
490493 sql = text (
491494 """
492495 SELECT
@@ -495,13 +498,13 @@ async def get_workspace_by_name(self, name: str) -> Optional[Workspace]:
495498 WHERE name = :name AND deleted_at IS NULL
496499 """
497500 )
498- conditions = { " name" : name }
501+ conditions = GetWorkspaceByNameConditions ( name = name ). get_conditions ()
499502 workspaces = await self ._exec_select_conditions_to_pydantic (
500- Workspace , sql , conditions , should_raise = True
503+ WorkspaceRow , sql , conditions , should_raise = True
501504 )
502505 return workspaces [0 ] if workspaces else None
503506
504- async def get_archived_workspace_by_name (self , name : str ) -> Optional [Workspace ]:
507+ async def get_archived_workspace_by_name (self , name : str ) -> Optional [WorkspaceRow ]:
505508 sql = text (
506509 """
507510 SELECT
@@ -510,9 +513,9 @@ async def get_archived_workspace_by_name(self, name: str) -> Optional[Workspace]
510513 WHERE name = :name AND deleted_at IS NOT NULL
511514 """
512515 )
513- conditions = { " name" : name }
516+ conditions = GetWorkspaceByNameConditions ( name = name ). get_conditions ()
514517 workspaces = await self ._exec_select_conditions_to_pydantic (
515- Workspace , sql , conditions , should_raise = True
518+ WorkspaceRow , sql , conditions , should_raise = True
516519 )
517520 return workspaces [0 ] if workspaces else None
518521
0 commit comments