mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Migrate DB setup to use DI (#15324)
This commit is contained in:
committed by
GitHub
parent
c061acc01c
commit
8591c2e0d1
@@ -6,6 +6,7 @@ import { BinaryDataService, InstanceSettings } from 'n8n-core';
|
||||
import type { ExecutionStatus, IWorkflowBase } from 'n8n-workflow';
|
||||
|
||||
import { Time } from '@/constants';
|
||||
import { DbConnection } from '@/databases/db-connection';
|
||||
import { ExecutionsPruningService } from '@/services/pruning/executions-pruning.service';
|
||||
|
||||
import {
|
||||
@@ -34,6 +35,7 @@ describe('softDeleteOnPruningCycle()', () => {
|
||||
pruningService = new ExecutionsPruningService(
|
||||
mockLogger(),
|
||||
instanceSettings,
|
||||
Container.get(DbConnection),
|
||||
Container.get(ExecutionRepository),
|
||||
mockInstance(BinaryDataService),
|
||||
executionsConfig,
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
newWorkflow,
|
||||
} from './shared/db/workflows';
|
||||
import * as testDb from './shared/test-db';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
|
||||
describe('ImportService', () => {
|
||||
let importService: ImportService;
|
||||
@@ -37,9 +36,7 @@ describe('ImportService', () => {
|
||||
|
||||
tagRepository = Container.get(TagRepository);
|
||||
|
||||
const credentialsRepository = mockInstance(CredentialsRepository);
|
||||
|
||||
credentialsRepository.find.mockResolvedValue([]);
|
||||
const credentialsRepository = Container.get(CredentialsRepository);
|
||||
|
||||
importService = new ImportService(mock(), credentialsRepository, tagRepository);
|
||||
});
|
||||
|
||||
@@ -5,8 +5,8 @@ import type { DataSourceOptions } from '@n8n/typeorm';
|
||||
import { DataSource as Connection } from '@n8n/typeorm';
|
||||
import { randomString } from 'n8n-workflow';
|
||||
|
||||
import { getOptionOverrides } from '@/databases/config';
|
||||
import * as Db from '@/db';
|
||||
import { DbConnection } from '@/databases/db-connection';
|
||||
import { DbConnectionOptions } from '@/databases/db-connection-options';
|
||||
|
||||
export const testDbPrefix = 'n8n_test_';
|
||||
|
||||
@@ -34,20 +34,23 @@ export async function init() {
|
||||
globalConfig.database.mysqldb.database = testDbName;
|
||||
}
|
||||
|
||||
await Db.init();
|
||||
await Db.migrate();
|
||||
const dbConnection = Container.get(DbConnection);
|
||||
await dbConnection.init();
|
||||
await dbConnection.migrate();
|
||||
}
|
||||
|
||||
export function isReady() {
|
||||
return Db.connectionState.connected && Db.connectionState.migrated;
|
||||
const { connectionState } = Container.get(DbConnection);
|
||||
return connectionState.connected && connectionState.migrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop test DB, closing bootstrap connection if existing.
|
||||
*/
|
||||
export async function terminate() {
|
||||
await Db.close();
|
||||
Db.connectionState.connected = false;
|
||||
const dbConnection = Container.get(DbConnection);
|
||||
await dbConnection.close();
|
||||
dbConnection.connectionState.connected = false;
|
||||
}
|
||||
|
||||
type EntityName = keyof typeof entities | 'InsightsRaw' | 'InsightsByPeriod' | 'InsightsMetadata';
|
||||
@@ -71,7 +74,7 @@ export const getBootstrapDBOptions = (dbType: 'postgresdb' | 'mysqldb'): DataSou
|
||||
const type = dbType === 'postgresdb' ? 'postgres' : 'mysql';
|
||||
return {
|
||||
type,
|
||||
...getOptionOverrides(dbType),
|
||||
...Container.get(DbConnectionOptions).getOverrides(dbType),
|
||||
database: type,
|
||||
entityPrefix: globalConfig.database.tablePrefix,
|
||||
schema: dbType === 'postgresdb' ? globalConfig.database.postgresdb.schema : undefined,
|
||||
|
||||
Reference in New Issue
Block a user