sequelize-cli db:migrate always using development environment
See original GitHub issueI am using dotenv package. I reuire the package on top. I also tried changing “development” to “test” or “production”, but still It’s always using “development”.
'use strict';
require('dotenv').config({path:'../../.env'})
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development'; // I tried changing 'development' to 'production' and 'test'
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
console.log(env)
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
console.log(config)
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
Here is my .env
file
//set environment for different configurations
NODE_ENV=test
//define port
PORT=4000
NODE_CONFIG_DIR =./src/config
When I run the server, then It uses test
environment.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
sequalize migration with dotenv - Stack Overflow
You can run migrations command by specifying the environment. sequelize db:migrate --env production. Share.
Read more >Migrations | Sequelize
With migrations you can transfer your existing database into another state and vice versa: Those ... npm install --save-dev sequelize-cli.
Read more >How I Setup Database Migration using Sequelize in ... - tekloon
A Node Project with sequelize-cli dependencies; models folder which contain all the model to the table. We shall always have the latest ...
Read more >5. Database Migrations with Sequelize - Why and How
Learn what migrations are and why you should always be using them in your web ... way to create and utilize migrations with...
Read more >Configuration - db-migrate - Read the Docs
For example, you might have a dev, test, and prod environment where you need ... If you use the dotenv package to manage...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oops, I just use this
npx sequelize db:migrate --env testing
You can just do this all time
--env production
, but I don’t like it this way. It would make sense to just let things works as it should and use my .env file instead