mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
fix(core): Upsert credentials and workflows in the import:* commands (#5231)
This commit is contained in:
committed by
GitHub
parent
237b1d8614
commit
259296c5c9
@@ -10,15 +10,14 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { Command, flags } from '@oclif/command';
|
||||
|
||||
import { INode, INodeCredentialsDetails, LoggerProxy } from 'n8n-workflow';
|
||||
|
||||
import fs from 'fs';
|
||||
import glob from 'fast-glob';
|
||||
import { UserSettings } from 'n8n-core';
|
||||
import type { EntityManager } from 'typeorm';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { getLogger } from '@/Logger';
|
||||
import config from '@/config';
|
||||
import * as Db from '@/Db';
|
||||
import { SharedWorkflow } from '@db/entities/SharedWorkflow';
|
||||
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
@@ -26,6 +25,7 @@ import { Role } from '@db/entities/Role';
|
||||
import { User } from '@db/entities/User';
|
||||
import { setTagsForImport } from '@/TagHelpers';
|
||||
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
|
||||
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
|
||||
|
||||
const FIX_INSTRUCTION =
|
||||
'Please fix the database by running ./packages/cli/bin/n8n user-management:reset';
|
||||
@@ -97,6 +97,8 @@ export class ImportWorkflowsCommand extends Command {
|
||||
}
|
||||
|
||||
try {
|
||||
disableAutoGeneratedIds(WorkflowEntity);
|
||||
|
||||
await Db.init();
|
||||
|
||||
await this.initOwnerWorkflowRole();
|
||||
@@ -207,21 +209,21 @@ export class ImportWorkflowsCommand extends Command {
|
||||
}
|
||||
|
||||
private async storeWorkflow(workflow: object, user: User) {
|
||||
const newWorkflow = new WorkflowEntity();
|
||||
|
||||
Object.assign(newWorkflow, workflow);
|
||||
|
||||
const savedWorkflow = await this.transactionManager.save<WorkflowEntity>(newWorkflow);
|
||||
|
||||
const newSharedWorkflow = new SharedWorkflow();
|
||||
|
||||
Object.assign(newSharedWorkflow, {
|
||||
workflow: savedWorkflow,
|
||||
user,
|
||||
role: this.ownerWorkflowRole,
|
||||
});
|
||||
|
||||
await this.transactionManager.save<SharedWorkflow>(newSharedWorkflow);
|
||||
const result = await this.transactionManager.upsert(WorkflowEntity, workflow, ['id']);
|
||||
await this.transactionManager.upsert(
|
||||
SharedWorkflow,
|
||||
{
|
||||
workflowId: result.identifiers[0].id,
|
||||
userId: user.id,
|
||||
roleId: this.ownerWorkflowRole.id,
|
||||
},
|
||||
['workflowId', 'userId'],
|
||||
);
|
||||
if (config.getEnv('database.type') === 'postgresdb') {
|
||||
await this.transactionManager.query(
|
||||
"SELECT setval('workflow_entity_id_seq', (SELECT MAX(id) from workflow_entity))",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async getOwner() {
|
||||
|
||||
Reference in New Issue
Block a user