2023-02-21 04:21:14 +01:00
|
|
|
// drop postgres tables
|
|
|
|
// reset redis cache
|
|
|
|
import { config } from "../../src/config";
|
|
|
|
import { createClient } from "redis";
|
|
|
|
import { Pool } from "pg";
|
|
|
|
import { Logger } from "../../src/utils/logger";
|
|
|
|
|
|
|
|
export async function resetRedis() {
|
2023-02-22 07:15:49 +01:00
|
|
|
if (config?.redis?.enabled && config.mode === "test") {
|
2023-02-21 04:21:14 +01:00
|
|
|
const client = createClient(config.redis);
|
|
|
|
await client.connect();
|
|
|
|
await client.flushAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export async function resetPostgres() {
|
2023-02-22 07:15:49 +01:00
|
|
|
if (process.env.TEST_POSTGRES && config.mode == "test" && config.postgres) {
|
2023-02-21 04:21:14 +01:00
|
|
|
const pool = new Pool({ ...config.postgres });
|
|
|
|
await pool.query(`DROP DATABASE IF EXISTS "sponsorTimes"`);
|
|
|
|
await pool.query(`DROP DATABASE IF EXISTS "privateDB"`);
|
|
|
|
await pool.end().catch(err => Logger.error(`closing db (postgres): ${err}`));
|
|
|
|
}
|
|
|
|
}
|