Reputation: 4975
Sequelize's migrations creates a config.json, where I can define the database data for the development, production and live environment. So it knows in which database to run the migration files.
But we have defined those data already within a specific folder, inside specific configuration files for each environment, which we use for the current app. I would like to use the current database configuration of our app, within the sequelize migrations... Anyone who knows how to do this?
Or is there maybe a possibility to use variables inside sequelize's migrations, referring to the login data of the databases in our own files?
Upvotes: 2
Views: 3495
Reputation: 2596
We solved a similar concern by reading the Sequelize migration configuration into the app config.
In our config folder we have a index.js
. Here is how it looks like;
var fs = require('fs'),
conf = require('config-node')({ dir: 'config' });
// override the `sql` config using the configuration file used for
// Sequelize migrations
if (fs.existsSync(__dirname + '/config.json')){
conf.sql = require('./config')[process.env.NODE_ENV || 'development'];
}
module.exports = conf;
We run our main app like so;
NODE_ENV=production node main.js
And we import configuration into main.js
var config = require('./config'); // this requires the index.js
Upvotes: 2