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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 57 deletions

View file

@ -146,7 +146,7 @@
"@langchain/pinecone": "0.0.6",
"@langchain/redis": "0.0.5",
"@langchain/textsplitters": "0.0.2",
"@n8n/typeorm": "0.3.20-9",
"@n8n/typeorm": "0.3.20-10",
"@n8n/vm2": "3.9.20",
"@pinecone-database/pinecone": "2.2.1",
"@qdrant/js-client-rest": "1.9.0",

View file

@ -98,7 +98,7 @@
"@n8n/localtunnel": "2.1.0",
"@n8n/n8n-nodes-langchain": "workspace:*",
"@n8n/permissions": "workspace:*",
"@n8n/typeorm": "0.3.20-9",
"@n8n/typeorm": "0.3.20-10",
"@n8n_io/license-sdk": "2.12.0",
"@oclif/core": "3.18.1",
"@pinecone-database/pinecone": "2.1.0",
@ -165,7 +165,7 @@
"prom-client": "13.2.0",
"psl": "1.9.0",
"raw-body": "2.5.1",
"reflect-metadata": "0.2.1",
"reflect-metadata": "0.2.2",
"replacestream": "4.0.3",
"samlify": "2.8.9",
"semver": "7.5.4",

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;
}

View file

@ -3,11 +3,9 @@ import type { DataSourceOptions as ConnectionOptions } from '@n8n/typeorm';
import { MigrationExecutor, DataSource as Connection } from '@n8n/typeorm';
import { Container } from 'typedi';
import { Logger } from '@/Logger';
import { setSchema } from '@/Db';
import { getConnectionOptions } from '@db/config';
import type { Migration } from '@db/types';
import { wrapMigration } from '@db/utils/migrationHelpers';
import config from '@/config';
// This function is extracted to make it easier to unit test it.
// Mocking turned into a mess due to this command using typeorm and the db
@ -88,9 +86,6 @@ export class DbRevertMigrationCommand extends Command {
const connection = new Connection(connectionOptions);
await connection.initialize();
const dbType = config.getEnv('database.type');
if (dbType === 'postgresdb') await setSchema(connection);
const migrationExecutor = new MigrationExecutor(connection);
(connectionOptions.migrations as Migration[]).forEach(wrapMigration);

View file

@ -286,8 +286,8 @@ importers:
specifier: 0.0.2
version: 0.0.2
'@n8n/typeorm':
specifier: 0.3.20-9
version: 0.3.20-9(pg@8.11.3)(redis@4.6.12)(sqlite3@5.1.7)
specifier: 0.3.20-10
version: 0.3.20-10(pg@8.11.3)(redis@4.6.12)(sqlite3@5.1.7)
'@n8n/vm2':
specifier: 3.9.20
version: 3.9.20
@ -520,8 +520,8 @@ importers:
specifier: workspace:*
version: link:../@n8n/permissions
'@n8n/typeorm':
specifier: 0.3.20-9
version: 0.3.20-9(@sentry/node@7.87.0)(ioredis@5.3.2)(mysql2@3.9.7)(pg@8.11.3)(sqlite3@5.1.7)
specifier: 0.3.20-10
version: 0.3.20-10(@sentry/node@7.87.0)(ioredis@5.3.2)(mysql2@3.9.7)(pg@8.11.3)(sqlite3@5.1.7)
'@n8n_io/license-sdk':
specifier: 2.12.0
version: 2.12.0
@ -721,8 +721,8 @@ importers:
specifier: 2.5.1
version: 2.5.1
reflect-metadata:
specifier: 0.2.1
version: 0.2.1
specifier: 0.2.2
version: 0.2.2
replacestream:
specifier: 4.0.3
version: 4.0.3
@ -1013,7 +1013,7 @@ importers:
version: 6.1.5(@types/jest@29.5.3)(jest@29.6.2)(vitest@1.3.1)
'@testing-library/user-event':
specifier: ^14.5.1
version: 14.5.1(@testing-library/dom@9.3.3)
version: 14.5.1(@testing-library/dom@9.3.4)
'@testing-library/vue':
specifier: ^8.0.1
version: 8.0.1(@vue/compiler-sfc@3.4.21)(vue@3.4.21)
@ -3078,7 +3078,7 @@ packages:
engines: {node: '>=6.9.0'}
dependencies:
'@ampproject/remapping': 2.2.1
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
'@babel/generator': 7.23.6
'@babel/helper-compilation-targets': 7.23.6
'@babel/helper-module-transforms': 7.23.3(@babel/core@7.24.0)
@ -3409,7 +3409,7 @@ packages:
'@babel/helper-module-imports': 7.22.15
'@babel/helper-simple-access': 7.22.5
'@babel/helper-split-export-declaration': 7.22.6
'@babel/helper-validator-identifier': 7.22.20
'@babel/helper-validator-identifier': 7.24.6
dev: true
/@babel/helper-module-transforms@7.23.3(@babel/core@7.24.6):
@ -3423,7 +3423,7 @@ packages:
'@babel/helper-module-imports': 7.22.15
'@babel/helper-simple-access': 7.22.5
'@babel/helper-split-export-declaration': 7.22.6
'@babel/helper-validator-identifier': 7.22.20
'@babel/helper-validator-identifier': 7.24.6
dev: true
/@babel/helper-module-transforms@7.24.6(@babel/core@7.24.6):
@ -3623,7 +3623,7 @@ packages:
resolution: {integrity: sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/helper-validator-identifier': 7.22.20
'@babel/helper-validator-identifier': 7.24.6
chalk: 2.4.2
js-tokens: 4.0.0
dev: true
@ -4823,7 +4823,7 @@ packages:
resolution: {integrity: sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
'@babel/parser': 7.24.0
'@babel/types': 7.24.0
dev: true
@ -4832,7 +4832,7 @@ packages:
resolution: {integrity: sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
'@babel/parser': 7.24.0
'@babel/types': 7.24.0
dev: true
@ -4850,7 +4850,7 @@ packages:
resolution: {integrity: sha512-y6LPR+wpM2I3qJrsheCTwhIinzkETbplIgPBbwvqPKc+uljeA5gP+3nP8irdYt1mjQaDnlIcG+dw8OjAco4GXw==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
'@babel/generator': 7.22.9
'@babel/helper-environment-visitor': 7.22.5
'@babel/helper-function-name': 7.22.5
@ -4868,7 +4868,7 @@ packages:
resolution: {integrity: sha512-HfuJlI8qq3dEDmNU5ChzzpZRWq+oxCZQyMzIMEqLho+AQnhMnKQUzH6ydo3RBl/YjPCuk68Y6s0Gx0AeyULiWw==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
'@babel/generator': 7.23.6
'@babel/helper-environment-visitor': 7.22.20
'@babel/helper-function-name': 7.23.0
@ -5995,8 +5995,8 @@ packages:
/@jridgewell/source-map@0.3.2:
resolution: {integrity: sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==}
dependencies:
'@jridgewell/gen-mapping': 0.3.2
'@jridgewell/trace-mapping': 0.3.18
'@jridgewell/gen-mapping': 0.3.5
'@jridgewell/trace-mapping': 0.3.25
dev: true
/@jridgewell/sourcemap-codec@1.4.14:
@ -7206,8 +7206,8 @@ packages:
recast: 0.22.0
dev: false
/@n8n/typeorm@0.3.20-9(@sentry/node@7.87.0)(ioredis@5.3.2)(mysql2@3.9.7)(pg@8.11.3)(sqlite3@5.1.7):
resolution: {integrity: sha512-m9HrksvTftGQ2h6JLB3nq8uIaX19OPoa9MYLRqces4Y18r4b5mmdXH/qTrjxFiA1z4SP/KNCsvq90iRnT1pb1w==}
/@n8n/typeorm@0.3.20-10(@sentry/node@7.87.0)(ioredis@5.3.2)(mysql2@3.9.7)(pg@8.11.3)(sqlite3@5.1.7):
resolution: {integrity: sha512-YYQKkafEGqNAG+VgtGbJOWpcyF4ZsRJ+Q7qXigTXZFQb4xpL/+t0BXEMhy8Gw0OEjnZI5cbLGHcQtj7Xlfg7dw==}
engines: {node: '>=16.13.0'}
hasBin: true
peerDependencies:
@ -7285,7 +7285,7 @@ packages:
mkdirp: 2.1.3
mysql2: 3.9.7
pg: 8.11.3
reflect-metadata: 0.2.1
reflect-metadata: 0.2.2
sha.js: 2.4.11
sqlite3: 5.1.7
tarn: 3.0.2
@ -7296,8 +7296,8 @@ packages:
- supports-color
dev: false
/@n8n/typeorm@0.3.20-9(pg@8.11.3)(redis@4.6.12)(sqlite3@5.1.7):
resolution: {integrity: sha512-m9HrksvTftGQ2h6JLB3nq8uIaX19OPoa9MYLRqces4Y18r4b5mmdXH/qTrjxFiA1z4SP/KNCsvq90iRnT1pb1w==}
/@n8n/typeorm@0.3.20-10(pg@8.11.3)(redis@4.6.12)(sqlite3@5.1.7):
resolution: {integrity: sha512-YYQKkafEGqNAG+VgtGbJOWpcyF4ZsRJ+Q7qXigTXZFQb4xpL/+t0BXEMhy8Gw0OEjnZI5cbLGHcQtj7Xlfg7dw==}
engines: {node: '>=16.13.0'}
hasBin: true
peerDependencies:
@ -7373,7 +7373,7 @@ packages:
mkdirp: 2.1.3
pg: 8.11.3
redis: 4.6.12
reflect-metadata: 0.2.1
reflect-metadata: 0.2.2
sha.js: 2.4.11
sqlite3: 5.1.7
tarn: 3.0.2
@ -10252,13 +10252,13 @@ packages:
vitest: 1.3.1
dev: true
/@testing-library/user-event@14.5.1(@testing-library/dom@9.3.3):
/@testing-library/user-event@14.5.1(@testing-library/dom@9.3.4):
resolution: {integrity: sha512-UCcUKrUYGj7ClomOo2SpNVvx4/fkd/2BbIHDCle8A0ax+P3bU7yJwDBDrS6ZwdTMARWTGODX1hEsCcO+7beJjg==}
engines: {node: '>=12', npm: '>=6'}
peerDependencies:
'@testing-library/dom': '>=7.21.4'
dependencies:
'@testing-library/dom': 9.3.3
'@testing-library/dom': 9.3.4
dev: true
/@testing-library/user-event@14.5.2(@testing-library/dom@9.3.4):
@ -17800,7 +17800,7 @@ packages:
resolution: {integrity: sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@babel/code-frame': 7.22.5
'@babel/code-frame': 7.24.6
'@jest/types': 29.6.1
'@types/stack-utils': 2.0.1
chalk: 4.1.2
@ -17815,7 +17815,7 @@ packages:
resolution: {integrity: sha512-vnIGYEjoPSuRqV8W9t+Wow95SDp6KPX2Uf7EoeG9G99J2OVh7OSwpS4B6J0NfpEIpfkBNHlBZpA2rblEuEFhZQ==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@babel/code-frame': 7.22.5
'@babel/code-frame': 7.24.6
'@jest/types': 29.6.1
'@types/stack-utils': 2.0.1
chalk: 4.1.2
@ -20771,7 +20771,7 @@ packages:
resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==}
engines: {node: '>=8'}
dependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
error-ex: 1.3.2
json-parse-even-better-errors: 2.3.1
lines-and-columns: 1.2.4
@ -22352,8 +22352,8 @@ packages:
- react-native
dev: true
/reflect-metadata@0.2.1:
resolution: {integrity: sha512-i5lLI6iw9AU3Uu4szRNPPEkomnkjRTaVt9hy/bn5g/oSzekBSMeLZblcjP74AW0vBabqERLLIrz+gR8QYR54Tw==}
/reflect-metadata@0.2.2:
resolution: {integrity: sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==}
dev: false
/reftools@1.1.9:
@ -22635,7 +22635,7 @@ packages:
rollup: 3.29.4
typescript: 5.4.2
optionalDependencies:
'@babel/code-frame': 7.23.5
'@babel/code-frame': 7.24.6
dev: true
/rollup@3.29.4:
@ -24043,7 +24043,7 @@ packages:
uglify-js:
optional: true
dependencies:
'@jridgewell/trace-mapping': 0.3.18
'@jridgewell/trace-mapping': 0.3.25
jest-worker: 27.5.1
schema-utils: 3.1.1
serialize-javascript: 6.0.2