Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config option are not being picked up and used. #1139

Open
miqdadamirali opened this issue Aug 17, 2022 · 2 comments · May be fixed by #1512
Open

Config option are not being picked up and used. #1139

miqdadamirali opened this issue Aug 17, 2022 · 2 comments · May be fixed by #1512

Comments

@miqdadamirali
Copy link

miqdadamirali commented Aug 17, 2022

What you are doing?

Sequelize has a parameter in it's constructor called options https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-constructor
which has an item called define (more on the define) where additional items such as underscored, paranoid, timestamps etc. can be specified.

In my custom config file specified in the .sequelizerc, I have the that options object, however, they are not being picked up.
It seems like only the underscored work if and only if included in the model:generate as an option --underscored

// .sequelizerc
module.exports = {
  'config': path.resolve('src', 'myconfig.js'),
  'models-path': path.resolve('src', 'models')
};
// myconfig.js

const username = process.env.DATABASE_USERNAME;
const password = process.env.DATABASE_PASSWORD;
const database = process.env.DATABASE_NAME;
const host = process.env.DATABASE_HOST;
const dialect = 'postgres';
const options = {
  define: {
    underscored: true,
    paranoid: true,
  },
};

module.exports = { username, password, database, host, dialect, options };

// Also tried this:
const define = {
  underscored: true,
  paranoid: true
};

module.exports = { username, password, database, host, dialect, define };

What do you expect to happen?

I expect the config attributes to be picked up and work such that the migration file would include a deleted_at and the createdAt and updatedAt would be created_at and updated_at respectively.

What is actually happening?

It's not picking them up and using the default behaviour. It works exactly the same way with and without the options.
The deleted_at is not created. The createdAt and updatedAt remain the same.

Dialect: postgres
Sequelize CLI version: 6.4.1
Sequelize version: 6.21.3

Edit 1:

include the module.exports in the myconfig.js as per the comment: #1139 (comment)

@theredpea
Copy link

Hi your file myconfig js, it must define an export, agree? Please show us the export i.e. module.exports=... If this doesn't work, I wonder if sequelizerc files simply do not support the options arguments

@miqdadamirali
Copy link
Author

miqdadamirali commented Aug 18, 2022

Hi your file myconfig js, it must define an export, agree? Please show us the export i.e. module.exports=... If this doesn't work, I wonder if sequelizerc files simply do not support the options arguments

Agree, I have the module.exports.

const username = process.env.DATABASE_USERNAME;
const password = process.env.DATABASE_PASSWORD;
const database = process.env.DATABASE_NAME;
const host = process.env.DATABASE_HOST;
const dialect = 'postgres';
const options = {
  define: {
    underscored: true,
    paranoid: true,
  },
};

module.exports = { username, password, database, host, dialect, options };

Edit 1:

Updated the issue to include the above module.exports

@SteGun93 SteGun93 linked a pull request Jul 4, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants