removed error test log and added db creation

This commit is contained in:
bill bittner 2018-05-17 14:42:58 -07:00
parent 7394758d27
commit 10c6fb611f
3 changed files with 33 additions and 8 deletions

View file

@ -25,12 +25,11 @@ function LoggerConfig () {
});
// test all the log levels
logger.info('testing winston log levels...');
logger.error('Level 0');
logger.warn('Level 1');
logger.info('Level 2');
logger.verbose('Level 3');
logger.debug('Level 4');
logger.silly('Level 5');
logger.warn('Testing: Log Level 1');
logger.info('Testing: Log Level 2');
logger.verbose('Testing: Log Level 3');
logger.debug('Testing: Log Level 4');
logger.silly('Testing: Log Level 5');
};
};

View file

@ -13,6 +13,7 @@ const loggerConfig = require('./config/loggerConfig.js');
const mysqlConfig = require('./config/mysqlConfig.js');
const siteConfig = require('./config/siteConfig.js');
const slackConfig = require('./config/slackConfig.js');
const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js');
function Server () {
this.configureLogger = loggerConfig.update;
@ -81,8 +82,11 @@ function Server () {
const db = require('./server/models');
const PORT = siteConfig.details.port;
// sync sequelize
db.sequelize.sync()
// start the server
createDatabaseIfNotExists()
.then(() => {
db.sequelize.sync()
})
// start the server
.then(() => {
this.server.listen(PORT, () => {
logger.info(`Server is listening on PORT ${PORT}`);

View file

@ -0,0 +1,22 @@
const Sequelize = require('sequelize');
const createDatabaseIfNotExists = () => {
const {database, username, password} = require('../../../config/mysqlConfig.js');
const sequelize = new Sequelize('', username, password, {
dialect : 'mysql',
logging : true,
operatorsAliases: false,
});
console.log('username:', username, 'password:', password);
return new Promise((resolve, reject) => {
sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`)
.then(() => {
resolve();
})
.catch(error => {
reject(error);
});
});
};
module.exports = createDatabaseIfNotExists;