Skip to content

The open alternative to Salesforce, designed for AI.

Write workflow version content and drafts to core only (#27881)

Thomas Trompette14bab49811e0
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-mutation.workspace-service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-mutation.workspace-service.ts
index 777c318fc49..b549e83ae20 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-mutation.workspace-service.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-mutation.workspace-service.ts
@@ -29,7 +29,6 @@ import { getWorkflowCommandMenuItemLabel } from 'src/modules/workflow/workflow-t
import { CoreWorkflowIdResolutionService } from 'src/engine/core-modules/workflow/services/core-workflow-id-resolution.service';
import { CoreWorkflowListService } from 'src/engine/core-modules/workflow/services/core-workflow-list.service';
import { CoreWorkflowVersionWriteService } from 'src/engine/core-modules/workflow/services/core-workflow-version-write.service';
-import { assertExactlyOneMirrorRowWasWritten } from 'src/engine/core-modules/workflow/utils/assert-exactly-one-mirror-row-was-written.util';
import { CoreWorkflowAccessService } from 'src/engine/core-modules/workflow/services/core-workflow-access.service';
import { WorkflowRunRecordShareService } from 'src/engine/core-modules/workflow/services/workflow-run-record-share.service';
import { WorkflowCoreSyncService } from 'src/engine/core-modules/workflow/services/workflow-core-sync.service';
@@ -267,7 +266,7 @@ export class CoreWorkflowMutationWorkspaceService {
);
}
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId: initialDraft.id,
expectedVersion: initialDraft,
@@ -738,45 +737,18 @@ export class CoreWorkflowMutationWorkspaceService {
flatEntityMaps: flatWorkflowVersionMaps,
});
- // mirror first so the assert can veto before the core delete commits
- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {
- await this.workspaceOrmManager.runInWorkspaceTransaction(
- async (transactionScope) => {
- const mirrorDeleteResult = await transactionScope
- .getRepository<WorkflowVersionWorkspaceEntity>('workflowVersion', {
- shouldBypassPermissionChecks: true,
- })
- .softDelete({ coreWorkflowVersionId: coreVersion.id });
-
- assertExactlyOneMirrorRowWasWritten({
- affected: mirrorDeleteResult.affected,
- coreWorkflowVersionId: coreVersion.id,
- });
- },
- );
- }, buildSystemAuthContext(workspaceId));
-
- try {
- await this.runCoreWorkflowMigration({
- workspaceId,
- failureMessage:
- 'Multiple validation errors occurred while discarding workflow draft',
- operations: {
- workflowVersion: {
- flatEntityToCreate: [],
- flatEntityToDelete: [flatCoreVersionToDelete],
- flatEntityToUpdate: [],
- },
+ await this.runCoreWorkflowMigration({
+ workspaceId,
+ failureMessage:
+ 'Multiple validation errors occurred while discarding workflow draft',
+ operations: {
+ workflowVersion: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [flatCoreVersionToDelete],
+ flatEntityToUpdate: [],
},
- });
- } catch (error) {
- await this.restoreDiscardedMirrorVersion({
- workspaceId,
- coreWorkflowVersionId: coreVersion.id,
- });
-
- throw error;
- }
+ },
+ });
await this.workflowVersionCoreSyncService.invalidateAutomatedTriggerMaps(
workspaceId,
@@ -785,28 +757,6 @@ export class CoreWorkflowMutationWorkspaceService {
return coreVersion.coreWorkflowId;
}
- private async restoreDiscardedMirrorVersion({
- workspaceId,
- coreWorkflowVersionId,
- }: {
- workspaceId: string;
- coreWorkflowVersionId: string;
- }): Promise<void> {
- try {
- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {
- await this.workspaceOrmManager
- .getRepository<WorkflowVersionWorkspaceEntity>('workflowVersion', {
- shouldBypassPermissionChecks: true,
- })
- .restore({ coreWorkflowVersionId });
- }, buildSystemAuthContext(workspaceId));
- } catch (restoreError) {
- this.logger.error(
- `Failed to restore the mirror version for core version ${coreWorkflowVersionId} in workspace ${workspaceId}: ${restoreError}`,
- );
- }
- }
-
async updateWorkflowVisibility({
workspaceId,
userWorkspaceId,
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-mutation.workspace-service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-mutation.workspace-service.ts
index 50ee74e4b64..360fb199354 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-mutation.workspace-service.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-mutation.workspace-service.ts
@@ -118,7 +118,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
parentStepConnectionOptions,
});
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -176,7 +176,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
insertedStep: duplicatedStep,
});
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -254,7 +254,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
}
try {
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -311,7 +311,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
{ workspaceId, userWorkspaceId, coreWorkflowVersionId },
);
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -368,7 +368,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
stepToDeleteChildrenIds,
});
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -443,7 +443,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
nextStepIds: [...(trigger.nextStepIds ?? []), target],
};
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -485,7 +485,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
);
if (shouldPersist) {
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -548,7 +548,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
),
};
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -598,7 +598,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
step.id === source ? updatedSourceStep : step,
);
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -648,7 +648,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
: step;
});
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
@@ -694,10 +694,12 @@ export class CoreWorkflowVersionMutationWorkspaceService {
coreWorkflowId: string;
coreWorkflowVersionIdToCopy: string;
}): Promise<CoreWorkflowVersionDTO> {
- const { coreWorkflow, workspaceWorkflowId } =
- await this.coreWorkflowIdResolutionService.resolveWorkspaceWorkflowIdOrThrow(
- { workspaceId, userWorkspaceId, coreWorkflowId },
- );
+ const coreWorkflow =
+ await this.coreWorkflowIdResolutionService.resolveCoreWorkflowOrThrow({
+ workspaceId,
+ userWorkspaceId,
+ coreWorkflowId,
+ });
const versionToCopy = await this.coreWorkflowVersionRepository.findOne(
workspaceId,
@@ -742,7 +744,7 @@ export class CoreWorkflowVersionMutationWorkspaceService {
);
if (isDefined(existingDraft)) {
- await this.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await this.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId: existingDraft.id,
expectedVersion: existingDraft,
@@ -758,11 +760,11 @@ export class CoreWorkflowVersionMutationWorkspaceService {
}
const { coreWorkflowVersionId } =
- await this.coreWorkflowVersionWriteService.createDraftCoreWorkflowVersionAndMirror(
+ await this.coreWorkflowVersionWriteService.createDraftCoreWorkflowVersion(
{
workspaceId,
coreWorkflowId: coreWorkflow.id,
- workspaceWorkflowId,
+ workspaceWorkflowId: coreWorkflow.workspaceWorkflowId,
trigger: triggerToCopy,
steps: copiedSteps,
},
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-write.service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-write.service.ts
index 4a256b869ab..4b4c0d3abaf 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-write.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/core-workflow-version-write.service.ts
@@ -7,7 +7,6 @@ import isEqual from 'lodash.isequal';
import { DataSource } from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
-import { RecordPositionService } from 'src/engine/core-modules/record-position/services/record-position.service';
import {
WorkflowVersionEntity,
WorkflowVersionStatus as CoreWorkflowVersionStatus,
@@ -23,18 +22,11 @@ import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspa
import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
import { findFlatEntityByIdInFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps-or-throw.util';
import { WorkflowVersionCoreSyncService } from 'src/engine/core-modules/workflow/services/workflow-version-core-sync.service';
-import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
-import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';
-import { assertExactlyOneMirrorRowWasWritten } from 'src/engine/core-modules/workflow/utils/assert-exactly-one-mirror-row-was-written.util';
import { getCoreWorkflowVersionEditLockKey } from 'src/engine/core-modules/workflow/utils/get-core-workflow-version-edit-lock-key.util';
import {
WorkflowQueryValidationException,
WorkflowQueryValidationExceptionCode,
} from 'src/modules/workflow/common/exceptions/workflow-query-validation.exception';
-import {
- WorkflowVersionStatus,
- type WorkflowVersionWorkspaceEntity,
-} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowMetadataReadService } from 'src/modules/workflow/common/workspace-services/workflow-metadata-read.workspace-service';
import { assertWorkflowVersionIsNotMalformedOrThrow } from 'src/modules/workflow/workflow-builder/workflow-validation/utils/assert-workflow-version-is-not-malformed-or-throw.util';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
@@ -68,8 +60,6 @@ export class CoreWorkflowVersionWriteService {
private readonly flatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService,
private readonly coreWorkflowAccessService: CoreWorkflowAccessService,
private readonly workflowMetadataReadService: WorkflowMetadataReadService,
- private readonly workspaceOrmManager: WorkspaceOrmManager,
- private readonly recordPositionService: RecordPositionService,
private readonly postgresAdvisoryLockService: PostgresAdvisoryLockService,
) {}
@@ -169,7 +159,7 @@ export class CoreWorkflowVersionWriteService {
};
}
- async writeContentAndMirror({
+ async writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion,
@@ -249,26 +239,6 @@ export class CoreWorkflowVersionWriteService {
},
});
- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {
- await this.workspaceOrmManager.runInWorkspaceTransaction(
- async (transactionScope) => {
- const mirrorUpdateResult = await transactionScope
- .getRepository<WorkflowVersionWorkspaceEntity>(
- 'workflowVersion',
- {
- shouldBypassPermissionChecks: true,
- },
- )
- .update({ coreWorkflowVersionId }, { trigger, steps });
-
- assertExactlyOneMirrorRowWasWritten({
- affected: mirrorUpdateResult.affected,
- coreWorkflowVersionId,
- });
- },
- );
- }, buildSystemAuthContext(workspaceId));
-
if (isDefined(flatWorkflowVersion.coreWorkflowId)) {
await this.coreDataSource.query(
`UPDATE core."workflow" SET "updatedAt" = now() WHERE "workspaceId" = $1 AND "id" = $2`,
@@ -309,7 +279,7 @@ export class CoreWorkflowVersionWriteService {
return lockResult.value;
}
- async createDraftCoreWorkflowVersionAndMirror({
+ async createDraftCoreWorkflowVersion({
workspaceId,
coreWorkflowId,
workspaceWorkflowId,
@@ -318,7 +288,7 @@ export class CoreWorkflowVersionWriteService {
}: {
workspaceId: string;
coreWorkflowId: string;
- workspaceWorkflowId: string;
+ workspaceWorkflowId: string | null;
trigger: WorkflowTrigger | null;
steps: WorkflowAction[] | null;
}): Promise<{ coreWorkflowVersionId: string }> {
@@ -330,21 +300,6 @@ export class CoreWorkflowVersionWriteService {
});
const coreWorkflowVersionId = uuidv4();
- const workspaceWorkflowVersionId = uuidv4();
-
- const coreSiblingsCount = await this.countCoreVersions({
- workspaceId,
- coreWorkflowId,
- });
-
- const position = await this.recordPositionService.buildRecordPosition({
- value: 'first',
- objectMetadata: {
- isCustom: false,
- nameSingular: 'workflowVersion',
- },
- workspaceId,
- });
const { workspaceCustomFlatApplication } =
await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
@@ -371,7 +326,7 @@ export class CoreWorkflowVersionWriteService {
steps: steps ?? null,
status: CoreWorkflowVersionStatus.DRAFT,
isSystemSideEffect: false,
- workspaceWorkflowVersionId,
+ workspaceWorkflowVersionId: null,
applicationUniversalIdentifier:
workspaceCustomFlatApplication.universalIdentifier,
createdAt,
@@ -384,27 +339,6 @@ export class CoreWorkflowVersionWriteService {
},
});
- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {
- await this.workspaceOrmManager.runInWorkspaceTransaction(
- async (transactionScope) => {
- await transactionScope
- .getRepository<WorkflowVersionWorkspaceEntity>('workflowVersion', {
- shouldBypassPermissionChecks: true,
- })
- .insert({
- id: workspaceWorkflowVersionId,
- workflowId: workspaceWorkflowId,
- name: `v${coreSiblingsCount + 1}`,
- status: WorkflowVersionStatus.DRAFT,
- trigger,
- steps,
- position,
- coreWorkflowVersionId,
- });
- },
- );
- }, buildSystemAuthContext(workspaceId));
-
await this.workflowVersionCoreSyncService.invalidateAutomatedTriggerMaps(
workspaceId,
);
@@ -412,18 +346,6 @@ export class CoreWorkflowVersionWriteService {
return { coreWorkflowVersionId };
}
- async countCoreVersions({
- workspaceId,
- coreWorkflowId,
- }: {
- workspaceId: string;
- coreWorkflowId: string;
- }): Promise<number> {
- return this.coreWorkflowVersionRepository.count(workspaceId, {
- where: { coreWorkflowId },
- });
- }
-
private async assertContentIsNotMalformed({
workspaceId,
coreWorkflowVersionId,
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/utils/assert-exactly-one-mirror-row-was-written.util.ts b/packages/twenty-server/src/engine/core-modules/workflow/utils/assert-exactly-one-mirror-row-was-written.util.ts
deleted file mode 100644
index c02d6c89785..00000000000
--- a/packages/twenty-server/src/engine/core-modules/workflow/utils/assert-exactly-one-mirror-row-was-written.util.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { msg } from '@lingui/core/macro';
-
-import {
- WorkflowQueryValidationException,
- WorkflowQueryValidationExceptionCode,
-} from 'src/modules/workflow/common/exceptions/workflow-query-validation.exception';
-
-export const assertExactlyOneMirrorRowWasWritten = ({
- affected,
- coreWorkflowVersionId,
-}: {
- affected: number | null | undefined;
- coreWorkflowVersionId: string;
-}): void => {
- if (affected === 1) {
- return;
- }
-
- throw new WorkflowQueryValidationException(
- `Core workflow version '${coreWorkflowVersionId}' wrote ${affected ?? 0} workspace mirror rows instead of exactly one`,
- WorkflowQueryValidationExceptionCode.FORBIDDEN,
- {
- userFriendlyMessage: msg`Workflow version is not correctly linked to its mirror`,
- },
- );
-};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts b/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts
index 58f1a11984f..d988850e77c 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts
@@ -146,7 +146,7 @@ Call validate_workflow once when the workflow is complete, before activating.`,
},
);
- await deps.coreWorkflowVersionWriteService.writeContentAndMirror({
+ await deps.coreWorkflowVersionWriteService.writeContent({
workspaceId,
coreWorkflowVersionId,
expectedVersion: coreWorkflowVersion,
diff --git a/packages/twenty-server/test/integration/ai/suites/workflow-tools-core-ids.integration-spec.ts b/packages/twenty-server/test/integration/ai/suites/workflow-tools-core-ids.integration-spec.ts
index 9035717abb3..72a45c9352b 100644
--- a/packages/twenty-server/test/integration/ai/suites/workflow-tools-core-ids.integration-spec.ts
+++ b/packages/twenty-server/test/integration/ai/suites/workflow-tools-core-ids.integration-spec.ts
@@ -113,19 +113,6 @@ const readCoreVersionRow = async (coreWorkflowVersionId: string) => {
};
};
-const readWorkspaceVersionRow = async (workspaceWorkflowVersionId: string) => {
- const rows = await global.testDataSource.query(
- `SELECT id, steps, trigger FROM "${TEST_WORKSPACE_SCHEMA}"."workflowVersion" WHERE id = $1`,
- [workspaceWorkflowVersionId],
- );
-
- return rows[0] as {
- id: string;
- steps: { id: string; name: string }[] | null;
- trigger: { type: string } | null;
- };
-};
-
describe('workflow MCP tools on core identities (integration)', () => {
const coreWorkflowIdsToDelete: string[] = [];
@@ -271,7 +258,7 @@ describe('workflow MCP tools on core identities (integration)', () => {
expect(listed.workflows.length).toBeGreaterThan(0);
});
- it('should write an edit through the shared writer so the rollback mirror follows', async () => {
+ it('should write an edit through the shared writer', async () => {
const renamedStepName = `Renamed ${randomUUID()}`;
const coreVersion = await readCoreVersionRow(coreWorkflowVersionId);
const stepToUpdate = (
@@ -286,18 +273,12 @@ describe('workflow MCP tools on core identities (integration)', () => {
const updatedCoreVersion = await readCoreVersionRow(
coreWorkflowVersionId,
);
- const mirrorVersion = await readWorkspaceVersionRow(
- updatedCoreVersion.workspaceWorkflowVersionId as string,
- );
expect(
(updatedCoreVersion.steps as { id: string; name: string }[]).find(
(step) => step.id === loopBodyStepId,
)?.name,
).toBe(renamedStepName);
- expect(
- mirrorVersion.steps?.find((step) => step.id === loopBodyStepId)?.name,
- ).toBe(renamedStepName);
});
it('should read core content even after the workspace mirror content diverges', async () => {
diff --git a/packages/twenty-server/test/integration/email-tool/suites/outbound-email-body-formats.integration-spec.ts b/packages/twenty-server/test/integration/email-tool/suites/outbound-email-body-formats.integration-spec.ts
index 27480d974cf..e4ffc39df10 100644
--- a/packages/twenty-server/test/integration/email-tool/suites/outbound-email-body-formats.integration-spec.ts
+++ b/packages/twenty-server/test/integration/email-tool/suites/outbound-email-body-formats.integration-spec.ts
@@ -89,12 +89,12 @@ const storeBodyAsBeforeTheUpgrade = async (
FROM jsonb_array_elements(steps) step)`;
await global.testDataSource.query(
- `UPDATE "${WORKSPACE_SCHEMA}"."workflowVersion" SET ${replaceEmailStepBody} WHERE "coreWorkflowVersionId" = $2`,
+ `UPDATE core."workflowVersion" SET ${replaceEmailStepBody} WHERE "id" = $2`,
[legacyBody, coreWorkflowVersionId],
);
await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET ${replaceEmailStepBody} WHERE "id" = $2`,
- [legacyBody, coreWorkflowVersionId],
+ `UPDATE "${WORKSPACE_SCHEMA}"."workflowVersion" SET steps = (SELECT steps FROM core."workflowVersion" WHERE id = $1) WHERE "coreWorkflowVersionId" = $1`,
+ [coreWorkflowVersionId],
);
};
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts
index 48141a73840..ac44fcd5824 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-discard-draft.integration-spec.ts
@@ -9,11 +9,8 @@ import {
import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';
import { isDefined } from 'twenty-shared/utils';
-import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
-const WORKSPACE_SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);
-
const DISCARD_MUTATION = `
mutation Discard($input: DiscardCoreWorkflowDraftInput!) {
discardCoreWorkflowDraft(input: $input) {
@@ -26,7 +23,6 @@ const DISCARD_MUTATION = `
describe('discardCoreWorkflowDraft (e2e)', () => {
let coreWorkflowId: string;
let draftCoreVersionId: string;
- let draftWorkspaceVersionId: string;
beforeAll(async () => {
const createdCoreWorkflow = await createCoreWorkflow({
@@ -61,7 +57,6 @@ describe('discardCoreWorkflowDraft (e2e)', () => {
await coreWorkflowGraphqlRequest<{
createDraftFromCoreWorkflowVersion: {
id: string;
- workspaceWorkflowVersionId: string;
};
}>({
query: `
@@ -70,7 +65,6 @@ describe('discardCoreWorkflowDraft (e2e)', () => {
) {
createDraftFromCoreWorkflowVersion(input: $input) {
id
- workspaceWorkflowVersionId
}
}
`,
@@ -83,7 +77,6 @@ describe('discardCoreWorkflowDraft (e2e)', () => {
});
draftCoreVersionId = draftVersion.id;
- draftWorkspaceVersionId = draftVersion.workspaceWorkflowVersionId;
});
afterAll(async () => {
@@ -92,7 +85,7 @@ describe('discardCoreWorkflowDraft (e2e)', () => {
}
});
- it('soft-deletes the workspace draft, removes its core row and returns the refreshed workflow', async () => {
+ it('removes the core draft and returns the refreshed workflow', async () => {
const discardResponse = await workflowGraphqlRequest(DISCARD_MUTATION, {
input: { coreWorkflowVersionId: draftCoreVersionId },
});
@@ -105,13 +98,6 @@ describe('discardCoreWorkflowDraft (e2e)', () => {
expect(refreshedWorkflow.id).toBe(coreWorkflowId);
expect(refreshedWorkflow.statuses).not.toContain('DRAFT');
- const workspaceRows = await global.testDataSource.query(
- `SELECT "deletedAt" FROM "${WORKSPACE_SCHEMA}"."workflowVersion" WHERE id = $1`,
- [draftWorkspaceVersionId],
- );
-
- expect(workspaceRows[0]?.deletedAt).not.toBeNull();
-
const coreVersionRows = await global.testDataSource.query(
`SELECT id FROM core."workflowVersion" WHERE "workspaceId" = $1 AND id = $2`,
[SEED_APPLE_WORKSPACE_ID, draftCoreVersionId],
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
index 7f115b629ae..240a0a7d6b8 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
@@ -185,12 +185,31 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
fixtures.push(fixture);
await global.workflowTestServices.workspaceCache.invalidateAndRecompute(
workspaceId,
- ['workflowAutomatedTriggerMaps'],
+ [
+ 'flatWorkflowMaps',
+ 'flatWorkflowVersionMaps',
+ 'workflowAutomatedTriggerMaps',
+ ],
);
return fixture;
};
+ const markFixtureVersionAsDraft = async (fixture: Fixture) => {
+ await global.testDataSource.query(
+ `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.coreWorkflowVersionId],
+ );
+ await global.testDataSource.query(
+ `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.workflowVersionId],
+ );
+ await global.workflowTestServices.workspaceCache.invalidateAndRecompute(
+ workspaceId,
+ ['flatWorkflowVersionMaps', 'workflowAutomatedTriggerMaps'],
+ );
+ };
+
const getRun = async (runId: string) => {
const [run] = await global.testDataSource.query(
`SELECT * FROM "${schema}"."workflowRun" WHERE id = $1`,
@@ -2011,14 +2030,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
getAppProviderByClassName<WorkspaceMigrationValidateBuildAndRunService>(
'WorkspaceMigrationValidateBuildAndRunService',
);
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
+ await markFixtureVersionAsDraft(fixture);
const activateQuery =
'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }';
const firstActivation = await workflowGraphqlRequest(activateQuery, {
@@ -2087,14 +2099,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
it('rejects a draft edited while activation is being prepared', async () => {
const fixture = await createFixture();
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
+ await markFixtureVersionAsDraft(fixture);
const codeBuild = getAppProviderByClassName<CodeStepBuildService>(
'CodeStepBuildService',
);
@@ -2146,14 +2151,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
triggerType: 'CRON',
triggerSettings: { type: 'CUSTOM', pattern: '* * * * *' },
});
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
+ await markFixtureVersionAsDraft(fixture);
const cache = global.app.get<CacheStorageService>(
CacheStorageNamespace.ModuleWorkflow,
);
@@ -2202,14 +2200,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
it('rejects an overlapping builder edit without losing the successful edit and accepts a fresh retry', async () => {
const fixture = await createFixture();
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
+ await markFixtureVersionAsDraft(fixture);
const writer = getAppProviderByClassName<CoreWorkflowVersionWriteService>(
'CoreWorkflowVersionWriteService',
);
@@ -2268,13 +2259,8 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
'SELECT triggers, steps FROM core."workflowVersion" WHERE id = $1',
[fixture.coreWorkflowVersionId],
);
- const [mirror] = await global.testDataSource.query(
- `SELECT trigger, steps FROM "${schema}"."workflowVersion" WHERE id = $1`,
- [fixture.workflowVersionId],
- );
expect(core.triggers[0].name).toBe('Concurrent trigger edit');
expect(core.steps[0].position).toEqual({ x: 321, y: 654 });
- expect(mirror).toEqual({ trigger: core.triggers[0], steps: core.steps });
});
it('allows reconciliation to acquire core locks during a blocked rename', async () => {
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts
index 5a08f21287a..076a953d30d 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/duplicate-workflow.integration-spec.ts
@@ -9,13 +9,8 @@ import {
} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import { isDefined } from 'twenty-shared/utils';
-import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
-import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
-
const client = request(`http://localhost:${APP_PORT}`);
-const WORKSPACE_SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);
-
const graphql = (query: string, variables?: object) =>
client
.post('/graphql')
@@ -63,7 +58,7 @@ describe('duplicateCoreWorkflow (e2e)', () => {
}
});
- it('duplicates the workflow and mirrors the new draft version to the workspace', async () => {
+ it('duplicates the workflow into a new core draft version', async () => {
const response = await graphql(
`
mutation DuplicateCoreWorkflow($input: DuplicateCoreWorkflowInput!) {
@@ -104,18 +99,5 @@ describe('duplicateCoreWorkflow (e2e)', () => {
expect(duplicatedVersion.trigger?.type).toBe('MANUAL');
expect(Array.isArray(duplicatedVersion.steps)).toBe(true);
expect(duplicatedVersion.steps?.length).toBeGreaterThan(0);
-
- const mirrorRows = await global.testDataSource.query(
- `SELECT "id", "steps", "trigger", "status" FROM "${WORKSPACE_SCHEMA}"."workflowVersion"
- WHERE "workflowId" = $1 AND "deletedAt" IS NULL`,
- [duplicated.workspaceWorkflowId],
- );
-
- expect(mirrorRows).toHaveLength(1);
- expect(mirrorRows[0].id).toBe(duplicatedVersion.workspaceWorkflowVersionId);
- expect(mirrorRows[0].status).toBe('DRAFT');
- expect(Array.isArray(mirrorRows[0].steps)).toBe(true);
- expect(mirrorRows[0].steps.length).toBe(duplicatedVersion.steps?.length);
- expect(mirrorRows[0].trigger.type).toBe('MANUAL');
});
});