feat(core): Initial workflow history API (#7234)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Val
2023-09-27 15:22:39 +01:00
committed by GitHub
parent 5c57e2ccc3
commit 0083a9e45d
14 changed files with 474 additions and 17 deletions

View File

@@ -1,7 +1,8 @@
import { UserSettings } from 'n8n-core';
import type { DataSourceOptions as ConnectionOptions } from 'typeorm';
import type { DataSourceOptions as ConnectionOptions, Repository } from 'typeorm';
import { DataSource as Connection } from 'typeorm';
import { Container } from 'typedi';
import { v4 as uuid } from 'uuid';
import config from '@/config';
import * as Db from '@/Db';
@@ -26,12 +27,17 @@ import type { ExecutionData } from '@db/entities/ExecutionData';
import { generateNanoId } from '@db/utils/generators';
import { RoleService } from '@/services/role.service';
import { VariablesService } from '@/environments/variables/variables.service';
import { TagRepository, WorkflowTagMappingRepository } from '@/databases/repositories';
import {
TagRepository,
WorkflowHistoryRepository,
WorkflowTagMappingRepository,
} from '@/databases/repositories';
import { separate } from '@/utils';
import { randomPassword } from '@/Ldap/helpers';
import { TOTPService } from '@/Mfa/totp.service';
import { MfaService } from '@/Mfa/mfa.service';
import type { WorkflowHistory } from '@/databases/entities/WorkflowHistory';
export type TestDBType = 'postgres' | 'mysql';
@@ -118,7 +124,12 @@ export async function truncate(collections: CollectionName[]) {
}
for (const collection of rest) {
await Db.collections[collection].delete({});
if (typeof collection === 'string') {
await Db.collections[collection].delete({});
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await Container.get(collection as { new (): Repository<any> }).delete({});
}
}
}
@@ -572,6 +583,33 @@ export async function getVariableById(id: string) {
});
}
// ----------------------------------
// workflow history
// ----------------------------------
export async function createWorkflowHistoryItem(
workflowId: string,
data?: Partial<WorkflowHistory>,
) {
return Container.get(WorkflowHistoryRepository).save({
authors: 'John Smith',
connections: {},
nodes: [
{
id: 'uuid-1234',
name: 'Start',
parameters: {},
position: [-20, 260],
type: 'n8n-nodes-base.start',
typeVersion: 1,
},
],
versionId: uuid(),
...(data ?? {}),
workflowId,
});
}
// ----------------------------------
// connection options
// ----------------------------------