@@ -651,9 +651,16 @@ export class SimDatabase {
651651 }
652652
653653 async close ( ) : Promise < void > {
654- if ( this . userIds . length > 0 )
655- await this . sql `delete from "user" where id in ${ this . sql ( this . userIds ) } ` . catch ( ( ) => { } )
656- await this . sql . end ( { timeout : 5 } )
654+ try {
655+ if ( this . userIds . length > 0 )
656+ await this . sql . begin ( async ( tx ) => {
657+ await tx `delete from workspace where owner_id in ${ tx ( this . userIds ) } `
658+ await tx `delete from project where owner_id in ${ tx ( this . userIds ) } `
659+ await tx `delete from "user" where id in ${ tx ( this . userIds ) } `
660+ } )
661+ } finally {
662+ await this . sql . end ( { timeout : 5 } )
663+ }
657664 }
658665
659666 /** A user with a workspace, a session as the desktop sign-in creates, and one chat per title. */
@@ -671,6 +678,10 @@ export class SimDatabase {
671678 await tx `insert into user_stats (id, user_id) values (${ generateId ( ) } , ${ userId } )`
672679 await tx `insert into workspace (id, name, owner_id, billed_account_user_id)
673680 values (${ workspaceId } , 'Desktop tools E2E', ${ userId } , ${ userId } )`
681+ await tx `insert into project (id, name, owner_id)
682+ values (${ workspaceId } , 'E2E fixture project', ${ userId } )`
683+ await tx `insert into project_workspace (project_id, workspace_id)
684+ values (${ workspaceId } , ${ workspaceId } )`
674685 await tx `insert into permissions (id, user_id, entity_type, entity_id, permission_type)
675686 values (${ generateId ( ) } , ${ userId } , 'workspace', ${ workspaceId } , 'admin')`
676687 await tx `insert into session (id, token, user_id, user_agent, expires_at, created_at, updated_at)
0 commit comments