flexxnn / sequelize-auto-migrations

Migration generator && runner for sequelize
MIT License
259 stars 166 forks source link

migrate.js crash on index change #50

Open JolivetteSax opened 5 years ago

JolivetteSax commented 5 years ago

I have a model that blows up a diff migration because of a model with 2 indexes that haven't changed. It gets picked up as a diff but in the parsedifferences routine the rhs value is null so line 367 blows up. It seems I can only solve this by adding this check.

                    let index = _.clone(df.rhs);
                    // sometimes a diff is picked up with no RHS?
                    if (index)
                    {
                      index.actionType = 'addIndex';
                      index.tableName = tableName;
                      index.depends = [ tableName ];
                      actions.push(index);
                    }

This change makes the diff migration carry on and it seems to work fine. I've found that if I actually make a difference it also "works", but only one time. For example, I thought I fixed this by adding names to all my indexes.

My sequelize model has these indexes


    indexes: [
    {
      name: 'account_uuid_idx',
      unique: true,
      fields: ['uuid']
    },
    {
      name: 'account_username_btree_idx',
      method: 'BTREE',
      fields: ['username']
    }
    ]
  }```

Linux, node v10.15.3 , npm 6.8.0,  "sequelize-auto-migrations": "^1.0.3"

Thanks for your eyeballs!