feat(cli): create DB in start command if not exists (#285)

This commit is contained in:
Ali BARIN
2022-04-08 11:36:35 +02:00
committed by GitHub
parent 75eda7f2af
commit c227dc86bb
19 changed files with 211 additions and 126 deletions

View File

@@ -1,29 +1,3 @@
import appConfig from '../../src/config/app';
import logger from '../../src/helpers/logger';
import client from './client';
const dropDatabase = async () => {
if (appConfig.appEnv != 'development' && appConfig.appEnv != 'test') {
const errorMessage = 'Drop database command can be used only with development or test environments!'
logger.error(errorMessage)
return;
}
await client.connect();
await dropDatabaseAndUser();
await client.end();
}
const dropDatabaseAndUser = async() => {
await client.query(`DROP DATABASE IF EXISTS ${appConfig.postgresDatabase}`);
logger.info(`Database: ${appConfig.postgresDatabase} removed!`);
await client.query(`DROP USER IF EXISTS ${appConfig.postgresUsername}`);
logger.info(`Database User: ${appConfig.postgresUsername} removed!`);
}
import { dropDatabase } from './utils';
dropDatabase();