19
19
Alert ,
20
20
GetAlertsWithPromptAndOutputRow ,
21
21
GetPromptWithOutputsRow ,
22
+ GetWorkspaceByNameConditions ,
22
23
Output ,
23
24
Prompt ,
24
25
Session ,
25
- Workspace ,
26
- WorkspaceActive ,
26
+ WorkspaceRow ,
27
+ WorkspaceWithSessionInfo ,
27
28
)
28
29
from codegate .pipeline .base import PipelineContext
29
30
@@ -263,15 +264,17 @@ async def record_context(self, context: Optional[PipelineContext]) -> None:
263
264
except Exception as e :
264
265
logger .error (f"Failed to record context: { context } ." , error = str (e ))
265
266
266
- async def add_workspace (self , workspace_name : str ) -> Workspace :
267
+ async def add_workspace (self , workspace_name : str ) -> WorkspaceRow :
267
268
"""Add a new workspace to the DB.
268
269
269
270
This handles validation and insertion of a new workspace.
270
271
271
272
It may raise a ValidationError if the workspace name is invalid.
272
273
or a AlreadyExistsError if the workspace already exists.
273
274
"""
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
+ )
275
278
sql = text (
276
279
"""
277
280
INSERT INTO workspaces (id, name)
@@ -289,7 +292,7 @@ async def add_workspace(self, workspace_name: str) -> Workspace:
289
292
raise AlreadyExistsError (f"Workspace { workspace_name } already exists." )
290
293
return added_workspace
291
294
292
- async def update_workspace (self , workspace : Workspace ) -> Workspace :
295
+ async def update_workspace (self , workspace : WorkspaceRow ) -> WorkspaceRow :
293
296
sql = text (
294
297
"""
295
298
UPDATE workspaces SET
@@ -319,7 +322,7 @@ async def update_session(self, session: Session) -> Optional[Session]:
319
322
active_session = await self ._execute_update_pydantic_model (session , sql , should_raise = True )
320
323
return active_session
321
324
322
- async def soft_delete_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
325
+ async def soft_delete_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
323
326
sql = text (
324
327
"""
325
328
UPDATE workspaces
@@ -333,7 +336,7 @@ async def soft_delete_workspace(self, workspace: Workspace) -> Optional[Workspac
333
336
)
334
337
return deleted_workspace
335
338
336
- async def hard_delete_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
339
+ async def hard_delete_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
337
340
sql = text (
338
341
"""
339
342
DELETE FROM workspaces
@@ -346,7 +349,7 @@ async def hard_delete_workspace(self, workspace: Workspace) -> Optional[Workspac
346
349
)
347
350
return deleted_workspace
348
351
349
- async def recover_workspace (self , workspace : Workspace ) -> Optional [Workspace ]:
352
+ async def recover_workspace (self , workspace : WorkspaceRow ) -> Optional [WorkspaceRow ]:
350
353
sql = text (
351
354
"""
352
355
UPDATE workspaces
@@ -460,20 +463,20 @@ async def get_alerts_with_prompt_and_output(
460
463
)
461
464
return prompts
462
465
463
- async def get_workspaces (self ) -> List [WorkspaceActive ]:
466
+ async def get_workspaces (self ) -> List [WorkspaceWithSessionInfo ]:
464
467
sql = text (
465
468
"""
466
469
SELECT
467
- w.id, w.name, s.active_workspace_id
470
+ w.id, w.name, s.id as session_id
468
471
FROM workspaces w
469
472
LEFT JOIN sessions s ON w.id = s.active_workspace_id
470
473
WHERE w.deleted_at IS NULL
471
474
"""
472
475
)
473
- workspaces = await self ._execute_select_pydantic_model (WorkspaceActive , sql )
476
+ workspaces = await self ._execute_select_pydantic_model (WorkspaceWithSessionInfo , sql )
474
477
return workspaces
475
478
476
- async def get_archived_workspaces (self ) -> List [Workspace ]:
479
+ async def get_archived_workspaces (self ) -> List [WorkspaceRow ]:
477
480
sql = text (
478
481
"""
479
482
SELECT
@@ -483,10 +486,10 @@ async def get_archived_workspaces(self) -> List[Workspace]:
483
486
ORDER BY deleted_at DESC
484
487
"""
485
488
)
486
- workspaces = await self ._execute_select_pydantic_model (Workspace , sql )
489
+ workspaces = await self ._execute_select_pydantic_model (WorkspaceRow , sql )
487
490
return workspaces
488
491
489
- async def get_workspace_by_name (self , name : str ) -> Optional [Workspace ]:
492
+ async def get_workspace_by_name (self , name : str ) -> Optional [WorkspaceRow ]:
490
493
sql = text (
491
494
"""
492
495
SELECT
@@ -495,13 +498,13 @@ async def get_workspace_by_name(self, name: str) -> Optional[Workspace]:
495
498
WHERE name = :name AND deleted_at IS NULL
496
499
"""
497
500
)
498
- conditions = { " name" : name }
501
+ conditions = GetWorkspaceByNameConditions ( name = name ). get_conditions ()
499
502
workspaces = await self ._exec_select_conditions_to_pydantic (
500
- Workspace , sql , conditions , should_raise = True
503
+ WorkspaceRow , sql , conditions , should_raise = True
501
504
)
502
505
return workspaces [0 ] if workspaces else None
503
506
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 ]:
505
508
sql = text (
506
509
"""
507
510
SELECT
@@ -510,9 +513,9 @@ async def get_archived_workspace_by_name(self, name: str) -> Optional[Workspace]
510
513
WHERE name = :name AND deleted_at IS NOT NULL
511
514
"""
512
515
)
513
- conditions = { " name" : name }
516
+ conditions = GetWorkspaceByNameConditions ( name = name ). get_conditions ()
514
517
workspaces = await self ._exec_select_conditions_to_pydantic (
515
- Workspace , sql , conditions , should_raise = True
518
+ WorkspaceRow , sql , conditions , should_raise = True
516
519
)
517
520
return workspaces [0 ] if workspaces else None
518
521
0 commit comments