mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
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
This commit is contained in:
committed by
GitHub
parent
5c9b40117a
commit
99157cf581
@@ -1,47 +1,23 @@
|
||||
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';
|
||||
import { getBootstrapDBOptions } from './integration/shared/testDb';
|
||||
|
||||
export default async () => {
|
||||
const dbType = config.getEnv('database.type');
|
||||
const dbType = config.getEnv('database.type').replace(/db$/, '');
|
||||
if (dbType !== 'postgres' && dbType !== 'mysql') return;
|
||||
|
||||
if (dbType === 'postgresdb') {
|
||||
const bootstrapPostgres = await createConnection(getBootstrapPostgresOptions());
|
||||
const connection = await createConnection(getBootstrapDBOptions(dbType));
|
||||
|
||||
const results: { db_name: string }[] = await bootstrapPostgres.query(
|
||||
'SELECT datname as db_name FROM pg_database;',
|
||||
);
|
||||
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 = 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}`,
|
||||
);
|
||||
}
|
||||
const promises = databases.map((dbName) => connection.query(`DROP DATABASE ${dbName};`));
|
||||
await Promise.all(promises);
|
||||
await connection.close();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user