mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Move first batch of repositories to @n8n/db (#15130)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { CredentialsEntity } from '@n8n/db';
|
||||
import type { Project } from '@n8n/db';
|
||||
import type { CredentialSharingRole } from '@n8n/db';
|
||||
import type { User } from '@n8n/db';
|
||||
import type { ICredentialsDb } from '@n8n/db';
|
||||
import { CredentialsEntity } from '@n8n/db';
|
||||
import { CredentialsRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
|
||||
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
|
||||
import { ProjectRepository } from '@/databases/repositories/project.repository';
|
||||
import { SharedCredentialsRepository } from '@/databases/repositories/shared-credentials.repository';
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { ExecutionEntity } from '@n8n/db';
|
||||
import type { ExecutionData } from '@n8n/db';
|
||||
import { ExecutionDataRepository } from '@n8n/db';
|
||||
import { ExecutionMetadataRepository } from '@n8n/db';
|
||||
import { ExecutionRepository } from '@n8n/db';
|
||||
import { AnnotationTagRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { AnnotationVote, IWorkflowBase } from 'n8n-workflow';
|
||||
|
||||
import { AnnotationTagRepository } from '@/databases/repositories/annotation-tag.repository.ee';
|
||||
import { ExecutionDataRepository } from '@/databases/repositories/execution-data.repository';
|
||||
import { ExecutionMetadataRepository } from '@/databases/repositories/execution-metadata.repository';
|
||||
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
import { Telemetry } from '@/telemetry';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { AuthIdentity } from '@n8n/db';
|
||||
import { type User } from '@n8n/db';
|
||||
import { AuthIdentityRepository } from '@n8n/db';
|
||||
import { AuthUserRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { ApiKeyScope, GlobalRole } from '@n8n/permissions';
|
||||
import { hash } from 'bcryptjs';
|
||||
|
||||
import { AuthIdentityRepository } from '@/databases/repositories/auth-identity.repository';
|
||||
import { AuthUserRepository } from '@/databases/repositories/auth-user.repository';
|
||||
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
import { MfaService } from '@/mfa/mfa.service';
|
||||
import { TOTPService } from '@/mfa/totp.service';
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import type { entities } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { DataSourceOptions, Repository } from '@n8n/typeorm';
|
||||
import type { DataSourceOptions } from '@n8n/typeorm';
|
||||
import { DataSource as Connection } from '@n8n/typeorm';
|
||||
import { kebabCase } from 'lodash';
|
||||
import type { Class } from 'n8n-core';
|
||||
import { randomString } from 'n8n-workflow';
|
||||
|
||||
import { getOptionOverrides } from '@/databases/config';
|
||||
@@ -11,18 +10,13 @@ import * as Db from '@/db';
|
||||
|
||||
export const testDbPrefix = 'n8n_test_';
|
||||
|
||||
type Extensions = 'insights';
|
||||
|
||||
let loadedExtensions: Extensions[] = [];
|
||||
|
||||
/**
|
||||
* Initialize one test DB per suite run, with bootstrap connection if needed.
|
||||
*/
|
||||
export async function init(extensionNames: Extensions[] = []) {
|
||||
export async function init() {
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
const dbType = globalConfig.database.type;
|
||||
const testDbName = `${testDbPrefix}${randomString(6, 10).toLowerCase()}_${Date.now()}`;
|
||||
loadedExtensions = extensionNames;
|
||||
|
||||
if (dbType === 'postgresdb') {
|
||||
const bootstrapPostgres = await new Connection(
|
||||
@@ -56,71 +50,16 @@ export async function terminate() {
|
||||
Db.connectionState.connected = false;
|
||||
}
|
||||
|
||||
// Can't use `Object.keys(entities)` here because some entities have a `Entity` suffix, while the repositories don't
|
||||
const repositories = [
|
||||
'AnnotationTag',
|
||||
'AuthIdentity',
|
||||
'AuthProviderSyncHistory',
|
||||
'Credentials',
|
||||
'EventDestinations',
|
||||
'Execution',
|
||||
'ExecutionAnnotation',
|
||||
'ExecutionData',
|
||||
'ExecutionMetadata',
|
||||
'InstalledNodes',
|
||||
'InstalledPackages',
|
||||
'Project',
|
||||
'ProjectRelation',
|
||||
'Role',
|
||||
'ProcessedData',
|
||||
'Project',
|
||||
'ProjectRelation',
|
||||
'Settings',
|
||||
'SharedCredentials',
|
||||
'SharedWorkflow',
|
||||
'Tag',
|
||||
'TestDefinition',
|
||||
'TestMetric',
|
||||
'TestRun',
|
||||
'User',
|
||||
'Variables',
|
||||
'Webhook',
|
||||
'Workflow',
|
||||
'WorkflowHistory',
|
||||
'WorkflowStatistics',
|
||||
'WorkflowTagMapping',
|
||||
'ApiKey',
|
||||
'Folder',
|
||||
'InsightsRaw',
|
||||
'InsightsMetadata',
|
||||
'InsightsByPeriod',
|
||||
] as const;
|
||||
type EntityName = keyof typeof entities | 'InsightsRaw' | 'InsightsByPeriod' | 'InsightsMetadata';
|
||||
|
||||
/**
|
||||
* Truncate specific DB tables in a test DB.
|
||||
*/
|
||||
export async function truncate(names: Array<(typeof repositories)[number]>) {
|
||||
for (const name of names) {
|
||||
let RepositoryClass: Class<Repository<object>>;
|
||||
export async function truncate(entities: EntityName[]) {
|
||||
const connection = Container.get(Connection);
|
||||
|
||||
const fileName = `${kebabCase(name)}.repository`;
|
||||
const paths = [
|
||||
`@/databases/repositories/${fileName}.ee`,
|
||||
`@/databases/repositories/${fileName}`,
|
||||
];
|
||||
|
||||
for (const extension of loadedExtensions) {
|
||||
paths.push(
|
||||
`@/modules/${extension}/database/repositories/${fileName}`,
|
||||
`@/modules/${extension}/database/repositories/${fileName}.ee`,
|
||||
);
|
||||
}
|
||||
|
||||
RepositoryClass = (await Promise.any(paths.map(async (path) => await import(path))))[
|
||||
`${name}Repository`
|
||||
];
|
||||
|
||||
await Container.get(RepositoryClass).delete({});
|
||||
for (const name of entities) {
|
||||
await connection.getRepository(name).delete({});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user