Question
I have a nodejs
project that uses sequelizejs
and now the config file as a config.json
looks like this:
{
"development": {
"users": {
"username": "postgres",
"password": "admin",
"database": "users",
"host": "127.0.0.1",
"port": 5432,
"dialect": "postgres",
"dialectOptions": {
"ssl": false,
"useUTC": false
},
"logging": false,
"timezone": "+08:00"
}
}
}
Now, the .sequelizerc
file looks like this:
const path = require("path");
module.exports = {
config: path.resolve("./config/config.json"),
"models-path": path.resolve("./models"),
"seeders-path": path.resolve("./seeders"),
"migrations-path": path.resolve("./migrations"),
};
If anyone is wondering, the file tree for my seeders
folder looks like this:
📦seeders
┣ 📂products
┣ 📂test1
┗ 📂users
┃ ┣ 📜20230206125203-Users.js
┃ ┗ 📜20230206132648-UserProfiles.js
I run the command: npx sequelize-cli db:seed --seeders-path ./seeders/users --env development.users
but I received an error:
Sequelize CLI [Node: 16.17.0, CLI: 6.6.0, ORM: 6.29.1]
Loaded configuration file "config/config.json".
ERROR: Dialect needs to be explicitly supplied as of v4.0.0
My .env
already has a NODE_ENV=development
on it.
I read the whole documentation for sequelize
and it doesn't seem to provide a scenario where development
has nested values inside of it.
Interestingly, a user from this GitHub issue on sequelize-cli has a solution to their problem but they used a config.js
, but I still use config.json
on the .sequelizerc
and as I try to mimic their code, it still doesn't work for my case.
I believe the issue here resides in the config.json
being nested as development.users
but I don't seem to see anything on the documentation I have missed.
Feel free to answer the question on how can I work to seed my seeder file! Thanks
Answer
It would be great to see how you are using your configurations, based on your setup you should have something similar like the one below:
const config = require("./config.json");
sequelize = new Sequelize(
config.users.database,
config.users.username,
config.users.password,
{
host: config.users.host,
dialect: config.users.dialect,
logging: false,
}
);
or
sequelize = new Sequelize(process.env[config.use_env_variable], {
logging: false,
});
This answer was originally posted on Stack Overflow. You can find the full discussion here