mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
ci: Fix test database cleanup (no-changelog) (#6188)
This commit is contained in:
parent
82fe6383ef
commit
85a6ace56b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
// ----------------------------------
|
||||
|
|
|
@ -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};`));
|
||||
|
|
Loading…
Reference in a new issue