refactor(core): Migrate DB setup to use DI (#15324)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-05-13 13:28:41 +02:00
committed by GitHub
parent c061acc01c
commit 8591c2e0d1
35 changed files with 782 additions and 378 deletions

View File

@@ -11,7 +11,8 @@ import { Logger } from 'n8n-core';
import config from '@/config';
import { N8N_VERSION, TEMPLATES_DIR, inDevelopment, inTest } from '@/constants';
import * as Db from '@/db';
import { DbConnection } from '@/databases/db-connection';
import { ServiceUnavailableError } from '@/errors/response-errors/service-unavailable.error';
import { ExternalHooks } from '@/external-hooks';
import { rawBodyReader, bodyParser, corsMiddleware } from '@/middlewares';
import { send, sendErrorResponse } from '@/response-helper';
@@ -21,8 +22,6 @@ import { WaitingForms } from '@/webhooks/waiting-forms';
import { WaitingWebhooks } from '@/webhooks/waiting-webhooks';
import { createWebhookHandlerFor } from '@/webhooks/webhook-request-handler';
import { ServiceUnavailableError } from './errors/response-errors/service-unavailable.error';
@Service()
export abstract class AbstractServer {
protected logger: Logger;
@@ -35,6 +34,8 @@ export abstract class AbstractServer {
protected globalConfig = Container.get(GlobalConfig);
protected dbConnection = Container.get(DbConnection);
protected sslKey: string;
protected sslCert: string;
@@ -126,8 +127,10 @@ export abstract class AbstractServer {
res.send({ status: 'ok' });
});
const { connectionState } = this.dbConnection;
this.app.get('/healthz/readiness', (_req, res) => {
const { connected, migrated } = Db.connectionState;
const { connected, migrated } = connectionState;
if (connected && migrated) {
res.status(200).send({ status: 'ok' });
} else {
@@ -135,7 +138,6 @@ export abstract class AbstractServer {
}
});
const { connectionState } = Db;
this.app.use((_req, res, next) => {
if (connectionState.connected) {
if (connectionState.migrated) next();