Skip to content

Commit 10f0c8c

Browse files
committed
Fix project workflow data migration using the wrong current step
1 parent dab6f69 commit 10f0c8c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/components/project/workflow/migrations/step-history-to-workflow-events.migration.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Project, ProjectStep, ProjectType } from '../../dto';
1010
import { ProjectWorkflowRepository } from '../project-workflow.repository';
1111
import { ProjectWorkflowService } from '../project-workflow.service';
1212

13-
@Migration('2024-06-22T09:00:00')
13+
@Migration('2024-07-02T14:00:00')
1414
export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
1515
constructor(
1616
private readonly agents: SystemAgentRepository,
@@ -57,23 +57,27 @@ export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
5757
this.logger.notice(`Processing project ${i + 1}/${projects.length}`);
5858
}
5959

60-
for (const [i, step] of steps.entries()) {
60+
for (const [i, next] of steps.entries()) {
6161
if (i === 0) {
6262
continue;
6363
}
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();
6569
const fakeProject: Project = {
6670
id: project.id,
6771
type: project.type,
68-
step: { value: step.value, canRead: true, canEdit: true },
72+
step: { value: current.value, canRead: true, canEdit: true },
6973
} as any;
7074
// @ts-expect-error private but this is a migration
7175
const transitions = await this.workflow.resolveAvailable(
72-
step.value,
76+
current.value,
7377
{
7478
project: fakeProject,
7579
moduleRef: this.moduleRef,
76-
migrationPrevStep: prev.value,
80+
migrationPrevSteps: prev,
7781
},
7882
project,
7983
// 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 {
8286
this.fakeAdminSession,
8387
);
8488

85-
const transition = transitions.find((t) => t.to === step.value)?.key;
89+
const transition = transitions.find((t) => t.to === next.value)?.key;
8690

8791
events.push({
8892
project: project.id,
89-
to: step.value,
93+
to: next.value,
9094
transition,
91-
at: step.createdAt,
95+
at: next.createdAt,
9296
});
9397
}
9498
}

src/components/project/workflow/transitions/dynamic-step.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { ProjectWorkflowRepository } from '../project-workflow.repository';
77
export interface ResolveParams {
88
project: MaybeSecured<Project>;
99
moduleRef: ModuleRef;
10-
migrationPrevStep?: ProjectStep;
10+
migrationPrevSteps?: ProjectStep[];
1111
}
1212

1313
export const BackTo = (
1414
...steps: ProjectStep[]
1515
): DynamicState<Step, ResolveParams> => ({
1616
description: 'Back',
1717
relatedStates: steps,
18-
async resolve({ project, moduleRef, migrationPrevStep }) {
19-
if (migrationPrevStep) {
20-
return migrationPrevStep;
18+
async resolve({ project, moduleRef, migrationPrevSteps }) {
19+
if (migrationPrevSteps) {
20+
return migrationPrevSteps.find((s) => steps.includes(s)) ?? steps[0];
2121
}
2222
const repo = moduleRef.get(ProjectWorkflowRepository);
2323
const found = await repo.mostRecentStep(project.id, steps);

0 commit comments

Comments
 (0)