benjaminnaesen
6/8/2018 - 10:56 AM

Sequelize: .sequelizerc

.sequelizerc file that includes file paths to sequelize configuration.

const path = require('path');
const fs = require('fs');
const config = require(`${process.cwd()}/config`);
const env = process.env.NODE_ENV.toLowerCase();

// Preprocess the config file
const sequelizeConfig = {
	[env]: config.postgresql,
};

// Write this to the temp folder
const configFilePath = process.cwd() + "/.temp/sequelizeConfig.js";
fs.writeFileSync(configFilePath, `module.exports = ${JSON.stringify(sequelizeConfig)}`);

module.exports = {
	'config': path.resolve(configFilePath),
	'models-path': path.resolve('server', 'models'),
	'seeders-path': path.resolve('seeders'),
	'migrations-path': path.resolve('migrations')
}