From 80853fcf03736e95a7ac804b577058de17d72108 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 29 Nov 2026 12:31:02 +0100 Subject: [PATCH] fix(ci): the Postgres engine forks its context without reaching into nest Server lint: src/db may not import src/nest, so the Postgres engine opens the request context with RequestContext.create itself, as demo-reset and the backup restore already do. Server types: the base EntityManager has no execute(); RESTORE-002 reads through the connection. --- server/src/db/engine/postgres/postgres-engine.ts | 8 ++++---- server/tests/unit/db/restore-migrates-forward.test.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/db/engine/postgres/postgres-engine.ts b/server/src/db/engine/postgres/postgres-engine.ts index 3f305a8f5..23d2962b8 100644 --- a/server/src/db/engine/postgres/postgres-engine.ts +++ b/server/src/db/engine/postgres/postgres-engine.ts @@ -1,5 +1,4 @@ import type { DbEngineSettings } from '../../../app-config/db-settings'; -import { withRequestContext } from '../../../nest/database/request-context'; import { NO_SAFETY_NET } from '../../legacy-baseline'; import { finishSchemaBootstrap, type AnyOrm } from '../../orm'; import type { DatabaseEngine } from '../engine'; @@ -9,7 +8,7 @@ import { bootstrapPostgresSchema, defaultPostgresBootstrapDeps, type PostgresBoo import { pgServerAddress } from './server-address'; import { putTempSchemaLast } from './session-search-path'; import { sslOptionFor } from './ssl'; -import type { EntityManager } from '@mikro-orm/core'; +import { RequestContext, type EntityManager } from '@mikro-orm/core'; import type { DatabaseConnection } from 'kysely'; @@ -77,8 +76,9 @@ export class PostgresEngine implements DatabaseEngine { const deps = this.bootstrapDeps(this.settings.url); // Migrated in a request context of its own, so the migrations' transaction // never lands on a caller's EntityManager (a restore's request, #3264; see - // runSchemaBootstrap). - await withRequestContext(orm, () => + // runSchemaBootstrap). RequestContext directly: the data layer does not + // reach up into nest/ for the helper. + await RequestContext.create(orm.em, () => bootstrapPostgresSchema(orm, options.snapshot ? deps : { ...deps, safetyNet: NO_SAFETY_NET }), ); await finishSchemaBootstrap(orm); diff --git a/server/tests/unit/db/restore-migrates-forward.test.ts b/server/tests/unit/db/restore-migrates-forward.test.ts index f8ad48428..8e654091d 100644 --- a/server/tests/unit/db/restore-migrates-forward.test.ts +++ b/server/tests/unit/db/restore-migrates-forward.test.ts @@ -118,7 +118,7 @@ describe('a restored database is migrated forward', () => { const rows = (await em?.getConnection().execute('select count(*) as c from mikro_orm_migrations')) as Array<{ c: number }> | undefined; expect(rows?.[0]?.c).toBe(all.length); - await expect(em?.execute('select 1 as one')).resolves.toEqual([{ one: 1 }]); + await expect(em?.getConnection().execute('select 1 as one')).resolves.toEqual([{ one: 1 }]); }); } finally { await restored.close(true);