mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
🧪 Make PG truncation sequential
This commit is contained in:
@@ -2,7 +2,7 @@ import { exec as callbackExec } from 'child_process';
|
|||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
import { createConnection, getConnection, ConnectionOptions, Connection } from 'typeorm';
|
import { createConnection, getConnection, ConnectionOptions, Connection } from 'typeorm';
|
||||||
import { Credentials, UserSettings } from 'n8n-core';
|
import { UserSettings } from 'n8n-core';
|
||||||
|
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import {
|
import {
|
||||||
@@ -163,13 +163,15 @@ async function truncateMappingTables(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dbType === 'postgresdb') {
|
if (dbType === 'postgresdb') {
|
||||||
const promises = mappingTables.map((tableName) => {
|
const schema = config.getEnv('database.postgresdb.schema');
|
||||||
const schema = config.getEnv('database.postgresdb.schema');
|
|
||||||
const fullTableName = `${schema}.${tableName}`;
|
|
||||||
testDb.query(`TRUNCATE TABLE ${fullTableName} RESTART IDENTITY CASCADE;`);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(promises);
|
// `TRUNCATE` in postgres cannot be parallelized
|
||||||
|
for (const tableName of mappingTables) {
|
||||||
|
const fullTableName = `${schema}.${tableName}`;
|
||||||
|
await testDb.query(`TRUNCATE TABLE ${fullTableName} RESTART IDENTITY CASCADE;`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mysqldb, mariadb
|
// mysqldb, mariadb
|
||||||
@@ -210,16 +212,16 @@ export async function truncate(collections: Array<CollectionName>, testDbName: s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dbType === 'postgresdb') {
|
if (dbType === 'postgresdb') {
|
||||||
const truncationPromises = collections.map((collection) => {
|
const schema = config.getEnv('database.postgresdb.schema');
|
||||||
const schema = config.getEnv('database.postgresdb.schema');
|
|
||||||
|
// `TRUNCATE` in postgres cannot be parallelized
|
||||||
|
for (const collection of collections) {
|
||||||
const fullTableName = `${schema}.${toTableName(collection)}`;
|
const fullTableName = `${schema}.${toTableName(collection)}`;
|
||||||
|
await testDb.query(`TRUNCATE TABLE ${fullTableName} RESTART IDENTITY CASCADE;`);
|
||||||
|
}
|
||||||
|
|
||||||
return testDb.query(`TRUNCATE TABLE ${fullTableName} RESTART IDENTITY CASCADE;`);
|
return await truncateMappingTables(dbType, collections, testDb);
|
||||||
});
|
// return Promise.resolve([])
|
||||||
|
|
||||||
truncationPromises.push(truncateMappingTables(dbType, collections, testDb));
|
|
||||||
|
|
||||||
return Promise.all(truncationPromises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user