mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(core): Fix import command for workflows with old format(pre UM) (#5403)
* Replace invalid credentials when importing workflows * Remove useless console.logs
This commit is contained in:
@@ -27,6 +27,7 @@ import type { User } from '@db/entities/User';
|
|||||||
import { setTagsForImport } from '@/TagHelpers';
|
import { setTagsForImport } from '@/TagHelpers';
|
||||||
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
|
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
|
||||||
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
|
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
|
||||||
|
import { replaceInvalidCredentials } from '@/WorkflowHelpers';
|
||||||
|
|
||||||
const FIX_INSTRUCTION =
|
const FIX_INSTRUCTION =
|
||||||
'Please fix the database by running ./packages/cli/bin/n8n user-management:reset';
|
'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;
|
totalImported = files.length;
|
||||||
|
console.info(`Importing ${totalImported} workflows...`);
|
||||||
await Db.getConnection().transaction(async (transactionManager) => {
|
await Db.getConnection().transaction(async (transactionManager) => {
|
||||||
this.transactionManager = transactionManager;
|
this.transactionManager = transactionManager;
|
||||||
|
|
||||||
@@ -165,17 +166,26 @@ export class ImportWorkflowsCommand extends Command {
|
|||||||
this.transactionManager = transactionManager;
|
this.transactionManager = transactionManager;
|
||||||
|
|
||||||
for (const workflow of workflows) {
|
for (const workflow of workflows) {
|
||||||
|
let oldCredentialFormat = false;
|
||||||
if (credentials.length > 0) {
|
if (credentials.length > 0) {
|
||||||
workflow.nodes.forEach((node: INode) => {
|
workflow.nodes.forEach((node: INode) => {
|
||||||
this.transformCredentials(node, credentials);
|
this.transformCredentials(node, credentials);
|
||||||
|
|
||||||
if (!node.id) {
|
if (!node.id) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
node.id = uuid();
|
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')) {
|
if (Object.prototype.hasOwnProperty.call(workflow, 'tags')) {
|
||||||
await setTagsForImport(transactionManager, workflow, tags);
|
await setTagsForImport(transactionManager, workflow, tags);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user