-
Notifications
You must be signed in to change notification settings - Fork 51k
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
Changes from 20 commits
c901a9b
8e956c4
ee7ddff
bbc3af0
343299d
232d38e
194b5fa
950d726
20e35f2
69120a7
1bfc817
346a926
446cc96
b3b1c7a
48fd32c
d73e641
0ba99da
3b9de5c
b421d38
43322c1
8e67761
2fdc885
7c35aa0
f66b162
9625aec
e6907e7
2736a89
f84d1f4
fb1c30f
3d3b70d
c5f374f
5a44c1d
8269116
dc802f1
6f9130c
7939fb0
a4dc093
acb8fcf
8b3afb7
cea6e0f
56f92c0
56c30cc
0368bdc
5bea05f
f0ef29a
c2361e7
e4f0ff1
1f86751
123db55
110e5ae
3760bcb
92ab28c
dc154a3
0f8bcce
41062b7
fe653e7
b02abf0
1c4975b
fd139f9
2e5a093
e6b74ca
aa8a29f
4721f7e
fe34ed7
ba03d02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| ProjectRepository, | ||
| SharedWorkflowRepository, | ||
| WorkflowRepository, | ||
| WorkflowHistoryRepository, | ||
| } from '@n8n/db'; | ||
| import { Container } from '@n8n/di'; | ||
| import type { WorkflowSharingRole } from '@n8n/permissions'; | ||
|
|
@@ -185,3 +186,33 @@ export async function getAllSharedWorkflows() { | |
|
|
||
| export const getWorkflowById = async (id: string) => | ||
| await Container.get(WorkflowRepository).findOneBy({ id }); | ||
|
|
||
| /** | ||
| * Create a workflow history record for a workflow | ||
| * @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> { | ||
| await Container.get(WorkflowHistoryRepository).insert({ | ||
| workflowId: workflow.id, | ||
| versionId: workflow.versionId, | ||
| nodes: workflow.nodes, | ||
| connections: workflow.connections, | ||
| authors: user?.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> { | ||
| const workflowHistory = await Container.get(WorkflowHistoryRepository).findOneOrFail({ | ||
| where: { workflowId, versionId }, | ||
| }); | ||
|
|
||
| await Container.get(WorkflowRepository).update(workflowId, { | ||
| activeVersion: workflowHistory, | ||
| }); | ||
| } | ||
| 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 AddActiveVersionIdColumn1762819200000 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, | ||
| 'SET NULL', | ||
|
||
| ); | ||
|
|
||
| // 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']); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| type: object | ||
| additionalProperties: false | ||
| properties: | ||
| versionId: | ||
| type: string | ||
| readOnly: true | ||
| description: Unique identifier for this workflow version | ||
| example: 7c6b9e3f-8d4a-4b2c-9f1e-6a5d3b8c7e4f | ||
| workflowId: | ||
| type: string | ||
| readOnly: true | ||
| description: The workflow this version belongs to | ||
| example: 2tUt1wbLX592XDdX | ||
| nodes: | ||
| type: array | ||
| readOnly: true | ||
| items: | ||
| $ref: './node.yml' | ||
| connections: | ||
| type: object | ||
| readOnly: true | ||
| example: { Jira: { main: [[{ node: 'Jira', type: 'main', index: 0 }]] } } | ||
| authors: | ||
| type: string | ||
| readOnly: true | ||
| description: Comma-separated list of author IDs who contributed to this version | ||
| example: 1,2,3 | ||
| createdAt: | ||
| type: string | ||
| format: date-time | ||
| readOnly: true | ||
| updatedAt: | ||
| type: string | ||
| format: date-time | ||
| readOnly: true |
Uh oh!
There was an error while loading. Please reload this page.