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

@@ -4,16 +4,14 @@ import type { Knex } from 'knex';
import knexConfig from '../../knexfile';
import logger from '../helpers/logger';
const knexInstance: Knex = knex(knexConfig);
export const client: Knex = knex(knexConfig);
const CONNECTION_REFUSED = 'ECONNREFUSED';
knexInstance.raw('SELECT 1')
client.raw('SELECT 1')
.catch((err) => {
if (err.code === CONNECTION_REFUSED) {
logger.error('Make sure you have installed PostgreSQL and it is running.', err);
process.exit();
}
});
export default knexInstance;

View File

@@ -1,4 +1,4 @@
import { Model } from 'objection';
import database from './database';
import { client } from './database';
Model.knex(database)
Model.knex(client);