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);

View File

@@ -1,5 +1,5 @@
import winston from 'winston'
import appConfig from '../config/app'
import * as winston from 'winston';
import appConfig from '../config/app';
const levels = {
error: 0,
@@ -7,11 +7,11 @@ const levels = {
info: 2,
http: 3,
debug: 4,
}
};
const level = () => {
return appConfig.appEnv === 'development' ? 'debug' : 'info'
}
};
const colors = {
error: 'red',
@@ -19,9 +19,9 @@ const colors = {
info: 'green',
http: 'magenta',
debug: 'white',
}
};
winston.addColors(colors)
winston.addColors(colors);
const format = winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
@@ -29,7 +29,7 @@ const format = winston.format.combine(
winston.format.printf(
(info) => `${info.timestamp} [${info.level}]: ${info.message}`,
),
)
);
const transports = [
new winston.transports.Console(),
@@ -38,13 +38,13 @@ const transports = [
level: 'error',
}),
new winston.transports.File({ filename: 'logs/server.log' }),
]
];
const logger = winston.createLogger({
export const logger = winston.createLogger({
level: level(),
levels,
format,
transports,
})
});
export default logger
export default logger;

View File

@@ -13,7 +13,7 @@ class Connection extends Base {
formattedData?: IJSONObject;
userId!: string;
verified = false;
count: number;
count?: number;
static tableName = 'connections';