From fdf47a96dee8883b811249e1e427b764cab15004 Mon Sep 17 00:00:00 2001 From: agobrech <45268029+agobrech@users.noreply.github.com> Date: Thu, 9 Feb 2023 15:24:09 +0100 Subject: [PATCH] fix(core): Fix import command for workflows with old format(pre UM) (#5403) * Replace invalid credentials when importing workflows * Remove useless console.logs --- packages/cli/src/commands/import/workflow.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/import/workflow.ts b/packages/cli/src/commands/import/workflow.ts index 2828f04471..027c77bc58 100644 --- a/packages/cli/src/commands/import/workflow.ts +++ b/packages/cli/src/commands/import/workflow.ts @@ -27,6 +27,7 @@ import type { User } from '@db/entities/User'; import { setTagsForImport } from '@/TagHelpers'; import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces'; import { disableAutoGeneratedIds } from '@db/utils/commandHelpers'; +import { replaceInvalidCredentials } from '@/WorkflowHelpers'; const FIX_INSTRUCTION = 'Please fix the database by running ./packages/cli/bin/n8n user-management:reset'; @@ -125,7 +126,7 @@ export class ImportWorkflowsCommand extends Command { }); totalImported = files.length; - + console.info(`Importing ${totalImported} workflows...`); await Db.getConnection().transaction(async (transactionManager) => { this.transactionManager = transactionManager; @@ -165,17 +166,26 @@ export class ImportWorkflowsCommand extends Command { this.transactionManager = transactionManager; for (const workflow of workflows) { + let oldCredentialFormat = false; if (credentials.length > 0) { workflow.nodes.forEach((node: INode) => { this.transformCredentials(node, credentials); - if (!node.id) { // eslint-disable-next-line no-param-reassign node.id = uuid(); } + if (!node.credentials?.id) { + oldCredentialFormat = true; + } }); } - + if (oldCredentialFormat) { + try { + await replaceInvalidCredentials(workflow as unknown as WorkflowEntity); + } catch (error) { + console.log(error); + } + } if (Object.prototype.hasOwnProperty.call(workflow, 'tags')) { await setTagsForImport(transactionManager, workflow, tags); }