Skip to content

The open alternative to Salesforce, designed for AI.

fix(workflow): scope one-active-per-workflow index to workspace (#22795)

Thomas Trompettec1b62334b75f
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-instance-command-fast-1783512000000-create-workflow-version-core-table.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-instance-command-fast-1783512000000-create-workflow-version-core-table.ts
index e9412e808a3..f611d4b02b7 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-instance-command-fast-1783512000000-create-workflow-version-core-table.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-20/2-20-instance-command-fast-1783512000000-create-workflow-version-core-table.ts
@@ -31,7 +31,7 @@ export class CreateWorkflowVersionCoreTableFastInstanceCommand
);
await queryRunner.query(
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_WORKFLOW_VERSION_ONE_ACTIVE_PER_WORKFLOW"
- ON "core"."workflowVersion" ("workflowId")
+ ON "core"."workflowVersion" ("workspaceId", "workflowId")
WHERE "status" = 'ACTIVE'`,
);
}
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/entities/workflow-version.entity.ts b/packages/twenty-server/src/engine/core-modules/workflow/entities/workflow-version.entity.ts
index 00265e725ec..02835d09818 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/entities/workflow-version.entity.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/entities/workflow-version.entity.ts
@@ -25,10 +25,14 @@ export enum WorkflowVersionStatus {
upgradeCommandName: CREATE_WORKFLOW_VERSION_CORE_TABLE_UPGRADE_COMMAND_NAME,
})
@Index('IDX_WORKFLOW_VERSION_WORKSPACE_ID', ['workspaceId'])
-@Index('IDX_WORKFLOW_VERSION_ONE_ACTIVE_PER_WORKFLOW', ['workflowId'], {
- unique: true,
- where: `"status" = 'ACTIVE'`,
-})
+@Index(
+ 'IDX_WORKFLOW_VERSION_ONE_ACTIVE_PER_WORKFLOW',
+ ['workspaceId', 'workflowId'],
+ {
+ unique: true,
+ where: `"status" = 'ACTIVE'`,
+ },
+)
@Index('IDX_WORKFLOW_VERSION_APPLICATION_ID', ['applicationId'])
export class WorkflowVersionEntity extends SyncableEntity {
@PrimaryGeneratedColumn('uuid')