mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
027dfb2f0a
* ⚡ Enable `esModuleInterop` for /core * ⚡ Adjust imports in /core * ⚡ Enable `esModuleInterop` for /cli * ⚡ Adjust imports in /cli * ⚡ Enable `esModuleInterop` for /nodes-base * ⚡ Adjust imports in /nodes-base * ⚡ Make imports consistent * ⬆️ Upgrade TypeScript to 4.6 (#3109) * ⬆️ Upgrade TypeScript to 4.6 * 📦 Update package-lock.json * 🔧 Avoid erroring on untyped errors * 📘 Fix type error Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { createConnection } from 'typeorm';
|
|
import config from '../config';
|
|
import { exec } from 'child_process';
|
|
import { getBootstrapMySqlOptions, getBootstrapPostgresOptions } from './integration/shared/testDb';
|
|
import { BOOTSTRAP_MYSQL_CONNECTION_NAME } from './integration/shared/constants';
|
|
|
|
export default async () => {
|
|
const dbType = config.getEnv('database.type');
|
|
|
|
if (dbType === 'postgresdb') {
|
|
const bootstrapPostgres = await createConnection(getBootstrapPostgresOptions());
|
|
|
|
const results: { db_name: string }[] = await bootstrapPostgres.query(
|
|
'SELECT datname as db_name FROM pg_database;',
|
|
);
|
|
|
|
const promises = results
|
|
.filter(({ db_name: dbName }) => dbName.startsWith('pg_') && dbName.endsWith('_n8n_test'))
|
|
.map(({ db_name: dbName }) => bootstrapPostgres.query(`DROP DATABASE ${dbName};`));
|
|
|
|
await Promise.all(promises);
|
|
|
|
bootstrapPostgres.close();
|
|
}
|
|
|
|
if (dbType === 'mysqldb') {
|
|
const user = config.getEnv('database.mysqldb.user');
|
|
const password = config.getEnv('database.mysqldb.password');
|
|
const host = config.getEnv('database.mysqldb.host');
|
|
|
|
const bootstrapMySql = await createConnection(getBootstrapMySqlOptions());
|
|
|
|
const results: { Database: string }[] = await bootstrapMySql.query('SHOW DATABASES;');
|
|
|
|
const promises = results
|
|
.filter(({ Database: dbName }) => dbName.startsWith('mysql_') && dbName.endsWith('_n8n_test'))
|
|
.map(({ Database: dbName }) => bootstrapMySql.query(`DROP DATABASE ${dbName};`));
|
|
|
|
await Promise.all(promises);
|
|
|
|
await bootstrapMySql.close();
|
|
|
|
exec(
|
|
`echo "DROP DATABASE ${BOOTSTRAP_MYSQL_CONNECTION_NAME}" | mysql -h ${host} -u ${user} -p${password}`,
|
|
);
|
|
}
|
|
};
|