Developers Notes

My Journey as Software Architect

Sequelize Sync {alter:true} always creating new Indexes

i'm using sequelize for my project, and enable sync with alter table,

 

when i run the project, sequelize always create a new indexes,

 

usually, the code something like this.

const User = this.sequelize.define('testSync', {
            email: {
              type: Sequelize.STRING,
              unique: true
            },
          });

 

you can change into this, to make it not always create new indexes.

const User = this.sequelize.define('testSync', {
            email: {
              type: Sequelize.STRING
            },
          }, {
            indexes: [
              { fields: ['email'], unique: true }
            ]
          });

References:

{alter: true} creates new indexe even if exists · Issue #8984 · sequelize/sequelize
https://github.com/sequelize/sequelize/issues/8984