diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index f855aff86b..5cc910367d 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -25,23 +25,36 @@ import type { ICredentialsDb } from '@/Interfaces'; import { DB_INITIALIZATION_TIMEOUT } from './constants'; import { randomApiKey, randomEmail, randomName, randomString, randomValidPassword } from './random'; -import { getPostgresSchemaSection } from './utils'; import type { CollectionName, CredentialPayload, InstalledNodePayload, InstalledPackagePayload, + PostgresSchemaSection, } from './types'; export type TestDBType = 'postgres' | 'mysql'; +export const testDbPrefix = 'n8n_test_'; + +export function getPostgresSchemaSection( + schema = config.getSchema(), +): PostgresSchemaSection | null { + for (const [key, value] of Object.entries(schema)) { + if (key === 'postgresdb') { + return value._cvtProperties; + } + } + return null; +} + /** * Initialize one test DB per suite run, with bootstrap connection if needed. */ export async function init() { jest.setTimeout(DB_INITIALIZATION_TIMEOUT); const dbType = config.getEnv('database.type'); - const testDbName = `n8n_test_${randomString(6, 10)}_${Date.now()}`; + const testDbName = `${testDbPrefix}${randomString(6, 10)}_${Date.now()}`; if (dbType === 'sqlite') { // no bootstrap connection required diff --git a/packages/cli/test/integration/shared/utils.ts b/packages/cli/test/integration/shared/utils.ts index dbd9920a51..8ae489a250 100644 --- a/packages/cli/test/integration/shared/utils.ts +++ b/packages/cli/test/integration/shared/utils.ts @@ -51,7 +51,6 @@ import type { EndpointGroup, InstalledNodePayload, InstalledPackagePayload, - PostgresSchemaSection, } from './types'; import { licenseController } from '@/license/license.controller'; import { registerController } from '@/decorators'; @@ -760,22 +759,6 @@ export const setInstanceOwnerSetUp = async (value: boolean) => { ); }; -// ---------------------------------- -// misc -// ---------------------------------- - -export function getPostgresSchemaSection( - schema = config.getSchema(), -): PostgresSchemaSection | null { - for (const [key, value] of Object.entries(schema)) { - if (key === 'postgresdb') { - return value._cvtProperties; - } - } - - return null; -} - // ---------------------------------- // community nodes // ---------------------------------- diff --git a/packages/cli/test/teardown.ts b/packages/cli/test/teardown.ts index 07136f2ddb..339708d412 100644 --- a/packages/cli/test/teardown.ts +++ b/packages/cli/test/teardown.ts @@ -1,7 +1,7 @@ import 'tsconfig-paths/register'; import { DataSource as Connection } from 'typeorm'; import config from '@/config'; -import { getBootstrapDBOptions } from './integration/shared/testDb'; +import { getBootstrapDBOptions, testDbPrefix } from './integration/shared/testDb'; export default async () => { const dbType = config.getEnv('database.type').replace(/db$/, ''); @@ -14,9 +14,7 @@ export default async () => { dbType === 'postgres' ? 'SELECT datname as "Database" FROM pg_database' : 'SHOW DATABASES'; const results: Array<{ Database: string }> = await connection.query(query); const databases = results - .filter( - ({ Database: dbName }) => dbName.startsWith(`${dbType}_`) && dbName.endsWith('_n8n_test'), - ) + .filter(({ Database: dbName }) => dbName.startsWith(testDbPrefix)) .map(({ Database: dbName }) => dbName); const promises = databases.map(async (dbName) => connection.query(`DROP DATABASE ${dbName};`));