2018-05-17 14:42:58 -07:00
|
|
|
const Sequelize = require('sequelize');
|
2018-06-06 12:01:11 -07:00
|
|
|
const {database, username, password} = require('@config/mysqlConfig');
|
2018-05-17 14:42:58 -07:00
|
|
|
|
|
|
|
const createDatabaseIfNotExists = () => {
|
|
|
|
const sequelize = new Sequelize('', username, password, {
|
|
|
|
dialect : 'mysql',
|
2018-05-17 18:11:22 -07:00
|
|
|
logging : false,
|
2018-05-17 14:42:58 -07: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;
|