I am working on updating my sequezlie config file so that it runs off env variables when the cli migration command is run. My setup works fine for remote servers that enable the env variables stored, but my local environment (like all) does not unless dotenv
is run. I configured dotenv
in my config file only if the environment recognized is development
and my console log is outputting the correct process.env.DB_DIALECT
of postgres
, but for some reason, during the migration, sequelize is telling me to download mysql
. Can anyone help with this bizarre issue?
Here is the head of my terminal output and error message:
DEVELOPMENT DOTENV
postgres
Loaded configuration file "config/config.js".
Error: Please install mysql package manually
at new ConnectionManager (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:23:11)
at new MysqlDialect (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/dialects/mysql/index.js:12:28)
at new Sequelize (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/sequelize.js:220:18)
Here is my config file:
var express = require('express');
var app = express();
var path = require('path');
if(app.get('env') === 'development'){
console.log('DEVELOPMENT DOTENV')
require('dotenv').config();
};
console.log(process.env.DB_DIALECT) //postgres
module.exports = {
"development": {
"username": process.env.DB_LOCAL_USERNAME,
"password": process.env.DB_LOCAL_PASSWORD,
"database": process.env.DB_LOCAL_DATABASE,
"host": "127.0.0.1",
"dialect": process.env.DB_DIALECT,
"migrationStorageTableName": "sequelize_meta",
"autoMigrateOldSchema": true
},
"staging": {
"username": process.env.RDS_USERNAME,
"password": process.env.RDS_PASSWORD,
"database": process.env.RDS_DATABASE,
"host": process.env.RDS_HOSTNAME,
"dialect": process.env.DB_DIALECT,
"migrationStorageTableName": "sequelize_meta"
},
"production": {
"username": process.env.RDS_USERNAME,
"password": process.env.RDS_PASSWORD,
"database": process.env.RDS_DATABASE,
"host": process.env.RDS_HOSTNAME,
"dialect": process.env.DB_DIALECT,
"migrationStorageTableName": "sequelize_meta"
}
}
Here is my migration file:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
queryInterface.sequelize.query("ALTER TABLE organization ADD CONSTRAINT organization_user_id_fkey FOREIGN KEY (admin_id) REFERENCES synotate_user (user_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;");
},
down: function (queryInterface, Sequelize) {
queryInterface.sequelize.query("ALTER TABLE organization DROP CONSTRAINT organization_user_id_fkey;");
}
};