File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed
prisma/migrations/20251203163619_cascade_delete_workflowrun_deps Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -74,11 +74,6 @@ workflows:
7474 branches :
7575 only :
7676 - develop
77- - feat/ai-workflows
78- - pm-1955_2
79- - re-try-failed-jobs
80- - pm-2539
81- - pm-2177_fixes
8277
8378
8479 - ' build-prod ' :
Original file line number Diff line number Diff line change 1+ -- DropForeignKey
2+ ALTER TABLE " aiWorkflowRunItem" DROP CONSTRAINT " aiWorkflowRunItem_workflowRunId_fkey" ;
3+
4+ -- DropForeignKey
5+ ALTER TABLE " aiWorkflowRunItemComment" DROP CONSTRAINT " aiWorkflowRunItemComment_workflowRunItemId_fkey" ;
6+
7+ -- AddForeignKey
8+ ALTER TABLE " aiWorkflowRunItem" ADD CONSTRAINT " aiWorkflowRunItem_workflowRunId_fkey" FOREIGN KEY (" workflowRunId" ) REFERENCES " aiWorkflowRun" (" id" ) ON DELETE CASCADE ON UPDATE CASCADE;
9+
10+ -- AddForeignKey
11+ ALTER TABLE " aiWorkflowRunItemComment" ADD CONSTRAINT " aiWorkflowRunItemComment_workflowRunItemId_fkey" FOREIGN KEY (" workflowRunItemId" ) REFERENCES " aiWorkflowRunItem" (" id" ) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change @@ -2287,6 +2287,34 @@ export class SubmissionService {
22872287 } ) ;
22882288 }
22892289 }
2290+ const TERMINAL_STATUSES = [
2291+ 'COMPLETED' ,
2292+ 'FAILURE' ,
2293+ 'CANCELLED' ,
2294+ 'SUCCESS' ,
2295+ ] ;
2296+
2297+ const runs = await this . prisma . aiWorkflowRun . findMany ( {
2298+ where : { submissionId : id } ,
2299+ select : { id : true , status : true } ,
2300+ } ) ;
2301+
2302+ if ( runs . length > 0 ) {
2303+ const nonTerminal = runs . filter (
2304+ ( r ) => ! TERMINAL_STATUSES . includes ( r . status ) ,
2305+ ) ;
2306+
2307+ if ( nonTerminal . length > 0 ) {
2308+ throw new Error (
2309+ `Cannot delete submission: ${ nonTerminal . length } workflow run(s) still active.` ,
2310+ ) ;
2311+ }
2312+
2313+ await this . prisma . aiWorkflowRun . deleteMany ( {
2314+ where : { submissionId : id } ,
2315+ } ) ;
2316+ }
2317+
22902318 await this . prisma . submission . delete ( {
22912319 where : { id } ,
22922320 } ) ;
You can’t perform that action at this time.
0 commit comments