diff --git a/server/migrations/20230419132159-add-indexes-to-notifications.js b/server/migrations/20230419132159-add-indexes-to-notifications.js new file mode 100644 index 0000000000..f769b7615e --- /dev/null +++ b/server/migrations/20230419132159-add-indexes-to-notifications.js @@ -0,0 +1,36 @@ +"use strict"; + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.addIndex("notifications", ["createdAt"], { + transaction, + }); + await queryInterface.addIndex("notifications", ["event"], { + transaction, + }); + await queryInterface.addIndex("notifications", ["viewedAt"], { + where: { + viewedAt: { + [Sequelize.Op.is]: null, + }, + }, + transaction, + }); + }); + }, + + async down(queryInterface) { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.removeIndex("notifications", ["createdAt"], { + transaction, + }); + await queryInterface.removeIndex("notifications", ["event"], { + transaction, + }); + await queryInterface.removeIndex("notifications", ["viewedAt"], { + transaction, + }); + }); + }, +};