-
Notifications
You must be signed in to change notification settings - Fork 51.1k
feat(core): Use active version instead of current version (no-changelog) #21202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
c901a9b
Add activeVersionId to workflow entity
dariacodes 8e956c4
Refactor activate workflow logic to use active version
dariacodes ee7ddff
Fix activateAll and deactivateAll CLI commands
dariacodes bbc3af0
Fix migration to only use existing version ids
dariacodes 343299d
Add tests for the public endpoint, account for active being read-only
dariacodes 232d38e
Add tests for internal update endpoint
dariacodes 194b5fa
Fix executeErrorWorkflow to use active version on activation failure
dariacodes 950d726
Fix production webhooks to execute active version instead of draft
dariacodes 20e35f2
Update migration to not check for version existence anymore (all user…
dariacodes 69120a7
Remove fallbacks to current version
dariacodes 1bfc817
Merge branch 'master' into ado-4277-refactor
dariacodes 346a926
Roll back versionId change for V1 activate
dariacodes 446cc96
Update migration timestamp
dariacodes b3b1c7a
Merge branch 'master' into ado-4277-refactor
dariacodes 48fd32c
Add activeVersion object to response of getWorkflow(s) V1
dariacodes d73e641
Remove tests with versionId (will be moved to V2)
dariacodes 0ba99da
Merge branch 'master' into ado-4277-refactor
dariacodes 3b9de5c
Fix import
dariacodes b421d38
Remove WF history license artifacts from tests
dariacodes 43322c1
Update active version on PATCH only when needed
dariacodes 8e67761
Merge branch 'master' into ado-4277-refactor
dariacodes 2fdc885
Improve tests
dariacodes 7c35aa0
Fix import order
dariacodes f66b162
Remove an obsolete check
dariacodes 9625aec
Remove duplicate tests
dariacodes e6907e7
Add missing relation
dariacodes 2736a89
Fix api schema
dariacodes f84d1f4
Move active version flags to ref for api schema
dariacodes fb1c30f
Set active version on workflow creation (e.g. through import)
dariacodes 3d3b70d
Merge branch 'master' into ado-4277-refactor
dariacodes c5f374f
Update migration to never remove active versions from workflow history
dariacodes 5a44c1d
Add activeVersionId to workflow entity, update queries
dariacodes 8269116
Merge branch 'master' into ado-4277-refactor
dariacodes dc802f1
Fix entity truncate order in tests
dariacodes 6f9130c
Update pruning logic to not delete active versions as well
dariacodes 7939fb0
Improve cli workflow update commands tests
dariacodes a4dc093
Improve workflow repository tests
dariacodes acb8fcf
Move version saving up during workflow creation
dariacodes 8b3afb7
Attempt to solve foreign key circular dependencies for MySQL and MariaDB
dariacodes cea6e0f
Fix quotes in activateAll query
dariacodes 56f92c0
Add more truncation in tests
dariacodes 56c30cc
Truncate junction tables
dariacodes 0368bdc
Merge branch 'master' into ado-4277-refactor
dariacodes 5bea05f
Use activeVersionId on backend where active is used
dariacodes f0ef29a
Use activeVersionId on frontend where active is used
dariacodes c2361e7
Update tests
dariacodes e4f0ff1
Merge branch 'master' into ado-4277-refactor
dariacodes 1f86751
Fix lint issue
dariacodes 123db55
Fix mcp tests
dariacodes 110e5ae
Merge branch 'master' into ado-4277-refactor
dariacodes 3760bcb
Fix roll-back value
dariacodes 92ab28c
Merge branch 'master' into ado-4277-refactor
dariacodes dc154a3
Make the check in job processor more explicit
dariacodes 0f8bcce
Use only activeVersionId in source control import
dariacodes 41062b7
Return correct active status for execution workflow data
dariacodes fe653e7
Improve checks for active workflow manager
dariacodes b02abf0
Fix test active workflow manager test mocks
dariacodes 1c4975b
Remove activeVersionId from WorkflowDataUpdate
dariacodes fd139f9
Use the right workflow version in execute additional data
dariacodes 2e5a093
Remove activeVersionId filter from useWorkflowHelpers
dariacodes e6b74ca
Fix comments
dariacodes aa8a29f
Merge branch 'master' into ado-4277-refactor
dariacodes 4721f7e
Add a test checking that current version is used for manual executions
dariacodes fe34ed7
Rename util
dariacodes ba03d02
Update db workflow repo test
dariacodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,18 @@ export async function createManyWorkflows( | |
| return await Promise.all(workflowRequests); | ||
| } | ||
|
|
||
| export async function createManyActiveWorkflows( | ||
| amount: number, | ||
| attributes: Partial<IWorkflowDb> = {}, | ||
| userOrProject?: User | Project, | ||
| ) { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const workflowRequests = [...Array(amount)].map( | ||
| async (_) => await createActiveWorkflow(attributes, userOrProject), | ||
| ); | ||
| return await Promise.all(workflowRequests); | ||
| } | ||
|
|
||
| export async function shareWorkflowWithUsers(workflow: IWorkflowBase, users: User[]) { | ||
| const sharedWorkflows: Array<DeepPartial<SharedWorkflow>> = await Promise.all( | ||
| users.map(async (user) => { | ||
|
|
@@ -135,7 +147,7 @@ export async function getWorkflowSharing(workflow: IWorkflowBase) { | |
| */ | ||
| export async function createWorkflowWithTrigger( | ||
| attributes: Partial<IWorkflowDb> = {}, | ||
| user?: User, | ||
| userOrProject?: User | Project, | ||
| ) { | ||
| const workflow = await createWorkflow( | ||
| { | ||
|
|
@@ -170,7 +182,7 @@ export async function createWorkflowWithTrigger( | |
| }, | ||
| ...attributes, | ||
| }, | ||
| user, | ||
| userOrProject, | ||
| ); | ||
|
|
||
| return workflow; | ||
|
|
@@ -201,12 +213,12 @@ export async function createWorkflowWithHistory( | |
| */ | ||
| export async function createWorkflowWithTriggerAndHistory( | ||
| attributes: Partial<IWorkflowDb> = {}, | ||
| user?: User, | ||
| userOrProject?: User | Project, | ||
| ) { | ||
| const workflow = await createWorkflowWithTrigger(attributes, user); | ||
| const workflow = await createWorkflowWithTrigger(attributes, userOrProject); | ||
|
|
||
| // Create workflow history for the initial version | ||
| await createWorkflowHistory(workflow, user); | ||
| await createWorkflowHistory(workflow, userOrProject); | ||
|
|
||
| return workflow; | ||
| } | ||
|
|
@@ -227,12 +239,78 @@ export const getWorkflowById = async (id: string) => | |
| * @param workflow workflow to create history for | ||
| * @param user user who created the version (optional) | ||
| */ | ||
| export async function createWorkflowHistory(workflow: IWorkflowDb, user?: User): Promise<void> { | ||
| export async function createWorkflowHistory( | ||
| workflow: IWorkflowDb, | ||
| userOrProject?: User | Project, | ||
| ): Promise<void> { | ||
| await Container.get(WorkflowHistoryRepository).insert({ | ||
| workflowId: workflow.id, | ||
| versionId: workflow.versionId, | ||
| nodes: workflow.nodes, | ||
| connections: workflow.connections, | ||
| authors: userOrProject instanceof User ? userOrProject.email : '[email protected]', | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Set the active version for a workflow | ||
| * @param workflowId workflow ID | ||
| * @param versionId version ID to set as active | ||
| */ | ||
| export async function setActiveVersion(workflowId: string, versionId: string): Promise<void> { | ||
| await Container.get(WorkflowRepository) | ||
| .createQueryBuilder() | ||
| .update() | ||
| .set({ activeVersionId: versionId }) | ||
| .where('id = :workflowId', { workflowId }) | ||
| .execute(); | ||
| } | ||
|
|
||
| /** | ||
| * Create an active workflow with trigger, history, and activeVersionId set to the current version. | ||
| * This simulates a workflow that has been activated and is running. | ||
| * @param attributes workflow attributes | ||
| * @param user user to assign the workflow to | ||
| */ | ||
| export async function createActiveWorkflow( | ||
| attributes: Partial<IWorkflowDb> = {}, | ||
| userOrProject?: User | Project, | ||
| ) { | ||
| const workflow = await createWorkflowWithTriggerAndHistory( | ||
| { active: true, ...attributes }, | ||
| userOrProject, | ||
| ); | ||
|
|
||
| await setActiveVersion(workflow.id, workflow.versionId); | ||
|
|
||
| workflow.activeVersionId = workflow.versionId; | ||
| return workflow; | ||
| } | ||
|
|
||
| /** | ||
| * Create a workflow with a specific active version. | ||
| * This simulates a workflow where the active version differs from the current version. | ||
| * @param activeVersionId the version ID to set as active | ||
| * @param attributes workflow attributes | ||
| * @param user user to assign the workflow to | ||
| */ | ||
| export async function createWorkflowWithActiveVersion( | ||
| activeVersionId: string, | ||
| attributes: Partial<IWorkflowDb> = {}, | ||
| user?: User, | ||
| ) { | ||
| const workflow = await createWorkflowWithTriggerAndHistory({ active: true, ...attributes }, user); | ||
|
|
||
| await Container.get(WorkflowHistoryRepository).insert({ | ||
| workflowId: workflow.id, | ||
| versionId: activeVersionId, | ||
| nodes: workflow.nodes, | ||
| connections: workflow.connections, | ||
| authors: user?.email ?? '[email protected]', | ||
| }); | ||
|
|
||
| await setActiveVersion(workflow.id, activeVersionId); | ||
|
|
||
| workflow.activeVersionId = activeVersionId; | ||
| return workflow; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/@n8n/db/src/migrations/common/1763047800000-AddActiveVersionIdColumn.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { MigrationContext, ReversibleMigration } from '../migration-types'; | ||
|
|
||
| const WORKFLOWS_TABLE_NAME = 'workflow_entity'; | ||
| const WORKFLOW_HISTORY_TABLE_NAME = 'workflow_history'; | ||
|
|
||
| export class AddActiveVersionIdColumn1763047800000 implements ReversibleMigration { | ||
| async up({ | ||
| schemaBuilder: { addColumns, column, addForeignKey }, | ||
| queryRunner, | ||
| escape, | ||
| }: MigrationContext) { | ||
| const workflowsTableName = escape.tableName(WORKFLOWS_TABLE_NAME); | ||
|
|
||
| await addColumns(WORKFLOWS_TABLE_NAME, [column('activeVersionId').varchar(36)]); | ||
|
|
||
| await addForeignKey( | ||
| WORKFLOWS_TABLE_NAME, | ||
| 'activeVersionId', | ||
| [WORKFLOW_HISTORY_TABLE_NAME, 'versionId'], | ||
| undefined, | ||
| 'RESTRICT', | ||
| ); | ||
|
|
||
| // For existing ACTIVE workflows, set activeVersionId = versionId | ||
| const versionIdColumn = escape.columnName('versionId'); | ||
| const activeColumn = escape.columnName('active'); | ||
| const activeVersionIdColumn = escape.columnName('activeVersionId'); | ||
|
|
||
| await queryRunner.query( | ||
| `UPDATE ${workflowsTableName} | ||
| SET ${activeVersionIdColumn} = ${versionIdColumn} | ||
| WHERE ${activeColumn} = true`, | ||
| ); | ||
| } | ||
|
|
||
| async down({ schemaBuilder: { dropColumns, dropForeignKey } }: MigrationContext) { | ||
| await dropForeignKey(WORKFLOWS_TABLE_NAME, 'activeVersionId', [ | ||
| WORKFLOW_HISTORY_TABLE_NAME, | ||
| 'versionId', | ||
| ]); | ||
| await dropColumns(WORKFLOWS_TABLE_NAME, ['activeVersionId']); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.