@@ -10,7 +10,7 @@ import { Project, ProjectStep, ProjectType } from '../../dto';
10
10
import { ProjectWorkflowRepository } from '../project-workflow.repository' ;
11
11
import { ProjectWorkflowService } from '../project-workflow.service' ;
12
12
13
- @Migration ( '2024-06-22T09 :00:00' )
13
+ @Migration ( '2024-07-02T14 :00:00' )
14
14
export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
15
15
constructor (
16
16
private readonly agents : SystemAgentRepository ,
@@ -57,23 +57,27 @@ export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
57
57
this . logger . notice ( `Processing project ${ i + 1 } /${ projects . length } ` ) ;
58
58
}
59
59
60
- for ( const [ i , step ] of steps . entries ( ) ) {
60
+ for ( const [ i , next ] of steps . entries ( ) ) {
61
61
if ( i === 0 ) {
62
62
continue ;
63
63
}
64
- const prev = steps [ i - 1 ] ! ;
64
+ const current = steps [ i - 1 ] ! ;
65
+ const prev = steps
66
+ . slice ( 0 , Math . max ( 0 , i - 2 ) )
67
+ . map ( ( s ) => s . value )
68
+ . reverse ( ) ;
65
69
const fakeProject : Project = {
66
70
id : project . id ,
67
71
type : project . type ,
68
- step : { value : step . value , canRead : true , canEdit : true } ,
72
+ step : { value : current . value , canRead : true , canEdit : true } ,
69
73
} as any ;
70
74
// @ts -expect-error private but this is a migration
71
75
const transitions = await this . workflow . resolveAvailable (
72
- step . value ,
76
+ current . value ,
73
77
{
74
78
project : fakeProject ,
75
79
moduleRef : this . moduleRef ,
76
- migrationPrevStep : prev . value ,
80
+ migrationPrevSteps : prev ,
77
81
} ,
78
82
project ,
79
83
// We don't know who did it, so we can't confirm this was an official
@@ -82,13 +86,13 @@ export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
82
86
this . fakeAdminSession ,
83
87
) ;
84
88
85
- const transition = transitions . find ( ( t ) => t . to === step . value ) ?. key ;
89
+ const transition = transitions . find ( ( t ) => t . to === next . value ) ?. key ;
86
90
87
91
events . push ( {
88
92
project : project . id ,
89
- to : step . value ,
93
+ to : next . value ,
90
94
transition,
91
- at : step . createdAt ,
95
+ at : next . createdAt ,
92
96
} ) ;
93
97
}
94
98
}
0 commit comments