fix(core): Try setting postgres search_path on the database (#9530)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-05-30 12:09:49 +02:00
committed by GitHub
parent cadb59fecb
commit e55bf0393a
5 changed files with 35 additions and 57 deletions

View File

@@ -4,7 +4,6 @@ import type { EntityManager } from '@n8n/typeorm';
import { DataSource as Connection } from '@n8n/typeorm';
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
import config from '@/config';
import { inTest } from '@/constants';
import { wrapMigration } from '@db/utils/migrationHelpers';
import type { Migration } from '@db/types';
@@ -48,30 +47,14 @@ export async function transaction<T>(fn: (entityManager: EntityManager) => Promi
return await connection.transaction(fn);
}
export async function setSchema(conn: Connection) {
const schema = config.getEnv('database.postgresdb.schema');
const searchPath = ['public'];
if (schema !== 'public') {
await conn.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
searchPath.unshift(schema);
}
await conn.query(`SET search_path TO ${searchPath.join(',')};`);
}
export async function init(): Promise<void> {
if (connectionState.connected) return;
const dbType = config.getEnv('database.type');
const connectionOptions = getConnectionOptions();
connection = new Connection(connectionOptions);
Container.set(Connection, connection);
await connection.initialize();
if (dbType === 'postgresdb') {
await setSchema(connection);
}
connectionState.connected = true;
}