refactor(core): Move backend config to a separate package (no-changelog) (#9325)
This commit is contained in:
committed by
GitHub
parent
1d5b9836ca
commit
c7d4b471c4
@@ -1,10 +1,11 @@
|
||||
import { Container } from 'typedi';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { readFileSync, rmSync } from 'fs';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
import type { ObjectLiteral } from '@n8n/typeorm';
|
||||
import type { QueryRunner } from '@n8n/typeorm/query-runner/QueryRunner';
|
||||
import { ApplicationError, jsonParse } from 'n8n-workflow';
|
||||
import config from '@/config';
|
||||
|
||||
import { inTest } from '@/constants';
|
||||
import type { BaseMigration, Migration, MigrationContext, MigrationFn } from '@db/types';
|
||||
import { createSchemaBuilder } from '@db/dsl';
|
||||
@@ -89,10 +90,11 @@ function parseJson<T>(data: string | T): T {
|
||||
return typeof data === 'string' ? jsonParse<T>(data) : data;
|
||||
}
|
||||
|
||||
const dbType = config.getEnv('database.type');
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
const dbType = globalConfig.database.type;
|
||||
const isMysql = ['mariadb', 'mysqldb'].includes(dbType);
|
||||
const dbName = config.getEnv(`database.${dbType === 'mariadb' ? 'mysqldb' : dbType}.database`);
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
const dbName = globalConfig.database[dbType === 'mariadb' ? 'mysqldb' : dbType].database;
|
||||
const tablePrefix = globalConfig.database.tablePrefix;
|
||||
|
||||
const createContext = (queryRunner: QueryRunner, migration: Migration): MigrationContext => ({
|
||||
logger: Container.get(Logger),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
import { Container } from 'typedi';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import type { ValueTransformer, FindOperator } from '@n8n/typeorm';
|
||||
import config from '@/config';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
|
||||
export const idStringifier = {
|
||||
from: (value?: number): string | undefined => value?.toString(),
|
||||
@@ -29,7 +30,7 @@ export const objectRetriever: ValueTransformer = {
|
||||
*/
|
||||
const jsonColumn: ValueTransformer = {
|
||||
to: (value: object): string | object =>
|
||||
config.getEnv('database.type') === 'sqlite' ? JSON.stringify(value) : value,
|
||||
Container.get(GlobalConfig).database.type === 'sqlite' ? JSON.stringify(value) : value,
|
||||
from: (value: string | object): object => (typeof value === 'string' ? jsonParse(value) : value),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user