"use strict"; const fs = require('fs'), path = require('path'), Sequelize = require('sequelize'), config = require('config'); function init() { const db = { sequelize: new Sequelize(config.get("db.chats")), Sequelize: Sequelize }; return db.sequelize.authenticate().then(function () { const Chat = db.sequelize.define('chat', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, path: Sequelize.STRING, name: Sequelize.STRING, }, { timestamps: false, classMethods: { associate: function() { } } }); return db.sequelize.sync({ force: false }).then(function () { return db; }); }).catch(function (error) { console.log("ERROR: Failed to authenticate with CHATS DB"); console.log("ERROR: " + JSON.stringify(config.get("db"), null, 2)); console.log(error); throw error; }); } module.exports = init();