n8n/packages/cli/test/teardown.ts
Tomi Turtiainen 9a1cc56806
fix: Set '@typescript-eslint/return-await' rule to 'always' for node code (no-changelog) (#8363)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2024-01-17 17:08:50 +02:00

26 lines
952 B
TypeScript

import 'tsconfig-paths/register';
import { DataSource as Connection } from 'typeorm';
import config from '@/config';
import { getBootstrapDBOptions, testDbPrefix } from './integration/shared/testDb';
export default async () => {
const dbType = config.getEnv('database.type').replace(/db$/, '');
if (dbType !== 'postgres' && dbType !== 'mysql') return;
const connection = new Connection(getBootstrapDBOptions(dbType));
await connection.initialize();
const query =
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(testDbPrefix))
.map(({ Database: dbName }) => dbName);
const promises = databases.map(
async (dbName) => await connection.query(`DROP DATABASE ${dbName};`),
);
await Promise.all(promises);
await connection.destroy();
};