I'm just starting out with Sequelize in Node.js and finding the documentation really lacking. I have a 'db' module in which I connect to the database via Sequelize, and this reads in configuration from an application-wide config file at ./config.json relative to the root of my project. This is a nested configuration and extremely unlikely to be structured in the way that Sequelize wants a config file for the CLI.
Now I'm trying to use migrations and the documentation makes reference to a "config file". I know I can set the path to that config file, but what the heck do I put in it? It's not documented anywhere (that I've seen).
There are more stuff you could put into config file
var sequelize = new Sequelize(config.database.dbName, config.database.master.user, config.database.master.password, {
dialect: config.database.protocol,
port: config.database.port,
host: config.database.master.host,
/* You could setup replication as well
replication: {
read: [
{
host: config.database.master.host,
username: config.database.master.host,
password: config.database.master.password
},
{
host: config.database.master.host,
username: config.database.master.host,
password: config.database.master.password
}
],
write: {
host: config.database.master.host,
username: config.database.master.host,
password: config.database.master.password
}
*/
},
pool: {
maxConnections: config.database.pool.maxConnections,
maxIdleTime: config.database.pool.maxIdleTime
},
logging: false,
define: {
underscored: false,
freezeTableName: false,
syncOnAssociation: true,
charset: 'utf8',
collate: 'utf8_general_ci',
classMethods: {method1: function() {}},
instanceMethods: {method2: function() {}},
timestamps: true
schema: "prefix"
}
}),
I read the code to figure it out. It's a flat structure. I just rebuild the config in a different format from my own config.
var config = require('./config');
module.exports = {
database: config.database.name,
username: config.database.user,
password: config.database.pass,
dialect: 'postgres',
dialectModulePath: 'pg.js',
host: config.database.host,
port: config.database.port,
pool: config.database.pool
};