n8n/packages/cli/test/teardown.ts
कारतोफ्फेलस्क्रिप्ट™ 99157cf581
feat: setup nightly tests for postgres and mysql schemas (#4441)
* feat: unify Jest config

* feat: simplify DB setup for tests

* feat: setup nightly tests for postgres and mysql schemas
2022-10-25 22:06:03 +02:00

24 lines
888 B
TypeScript

import { createConnection } from 'typeorm';
import config from '../config';
import { getBootstrapDBOptions } from './integration/shared/testDb';
export default async () => {
const dbType = config.getEnv('database.type').replace(/db$/, '');
if (dbType !== 'postgres' && dbType !== 'mysql') return;
const connection = await createConnection(getBootstrapDBOptions(dbType));
const query =
dbType === 'postgres' ? 'SELECT datname as "Database" FROM pg_database' : 'SHOW DATABASES';
const results: { Database: string }[] = await connection.query(query);
const databases = results
.filter(
({ Database: dbName }) => dbName.startsWith(`${dbType}_`) && dbName.endsWith('_n8n_test'),
)
.map(({ Database: dbName }) => dbName);
const promises = databases.map((dbName) => connection.query(`DROP DATABASE ${dbName};`));
await Promise.all(promises);
await connection.close();
};