From c18b24564ff4669ecddaca360a8fbaf9ed7d84ff Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Wed, 19 Apr 2023 19:04:26 +0530 Subject: [PATCH] feat: add indexes --- ...0419132159-add-indexes-to-notifications.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 server/migrations/20230419132159-add-indexes-to-notifications.js 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, + }); + }); + }, +};