n8n/packages/cli/test/teardown.ts
Tomi Turtiainen 5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
refactor(core): Enable import/order eslint rule (#10794)
2024-09-12 19:07:18 +03:00

28 lines
1,011 B
TypeScript

import 'tsconfig-paths/register';
import { GlobalConfig } from '@n8n/config';
import { DataSource as Connection } from '@n8n/typeorm';
import { Container } from 'typedi';
import { getBootstrapDBOptions, testDbPrefix } from './integration/shared/test-db';
export default async () => {
const { type: dbType } = Container.get(GlobalConfig).database;
if (dbType !== 'postgresdb' && dbType !== 'mysqldb') return;
const connection = new Connection(getBootstrapDBOptions(dbType));
await connection.initialize();
const query =
dbType === 'postgresdb' ? '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();
};