2018-05-17 23:42:58 +02:00
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
|
|
|
|
const createDatabaseIfNotExists = () => {
|
|
|
|
const {database, username, password} = require('../../../config/mysqlConfig.js');
|
|
|
|
const sequelize = new Sequelize('', username, password, {
|
|
|
|
dialect : 'mysql',
|
2018-05-18 03:11:22 +02:00
|
|
|
logging : false,
|
2018-05-17 23:42:58 +02:00
|
|
|
operatorsAliases: false,
|
|
|
|
});
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`)
|
|
|
|
.then(() => {
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = createDatabaseIfNotExists;
|