I'm using the following index in my model definition right now:
{
name: 'unique_partner_id',
unique: true,
fields: ['partnerId'],
where: {
email: {
$ne: null
}
}
}
However, I want to use migrations instead of sync, so I'm trying to move this definition from model to the initial migration file.
There is a queryInterface.addIndex()
method, however, I can't find any documentation for it.
SO, how do I define a partial index using queryInterface
?
I was looking for how to do this in a model and your question answered that for me. So now I'm going to answer this for you! Here's the up function that worked for me:
up: function(queryInterface, Sequelize) {
return queryInterface.addIndex(
'tablename',
['column1', 'column2'],
{
name: 'indexname',
where: {column3: {[Sequelize.Op.ne]: null}}
}
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With