node.jssequelize.js

What goes in the Sequelize "config file"?


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).


Solution

  • 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
    };