mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Migrate DB setup to use DI (#15324)
This commit is contained in:
committed by
GitHub
parent
c061acc01c
commit
8591c2e0d1
@@ -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