From e7867e52e0a2723679ef5ca0406e360814b4c995 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 27 Jan 2022 19:51:31 -0800 Subject: [PATCH] chore: Database index improvements (#3027) --- .../migrations/20220127000000-index-fixes.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 server/migrations/20220127000000-index-fixes.js diff --git a/server/migrations/20220127000000-index-fixes.js b/server/migrations/20220127000000-index-fixes.js new file mode 100644 index 000000000..27c6638a1 --- /dev/null +++ b/server/migrations/20220127000000-index-fixes.js @@ -0,0 +1,44 @@ +"use strict"; + +module.exports = { + up: async (queryInterface) => { + await queryInterface.addIndex("views", ["lastEditingAt"], { + name: "views_last_editing_at", + }); + await queryInterface.addIndex("pins", ["teamId"], { + name: "pins_team_id", + }); + await queryInterface.addIndex("collections", ["teamId", "deletedAt"], { + name: "collections_team_id_deleted_at", + }); + await queryInterface.addIndex("stars", ["userId", "documentId"], { + name: "stars_user_id_document_id", + }); + await queryInterface.addIndex("documents", ["collectionId"], { + name: "documents_collection_id", + }); + await queryInterface.addIndex("documents", ["publishedAt"], { + name: "documents_published_at", + }); + await queryInterface.addIndex("documents", ["teamId", "deletedAt"], { + name: "documents_team_id", + }); + + // somehow these indexes were being used sometimes, but i'll never know how. + // Note: These are not recreated in the down method + await queryInterface.removeIndex("documents", "documents_id_atlas_id_published_at"); + await queryInterface.removeIndex("documents", "documents_id_team_id_deleted_at"); + await queryInterface.removeIndex("documents", "documents_id_deleted_at"); + await queryInterface.removeIndex("collections", "atlases_id_deleted_at"); + await queryInterface.removeIndex("collections", "atlases_id_team_id_deleted_at"); + }, + down: async (queryInterface) => { + await queryInterface.removeIndex("views", "views_last_editing_at"); + await queryInterface.removeIndex("pins", "pins_team_id"); + await queryInterface.removeIndex("collections", "collections_team_id_deleted_at"); + await queryInterface.removeIndex("stars", "stars_user_id_document_id"); + await queryInterface.removeIndex("documents", "documents_collection_id"); + await queryInterface.removeIndex("documents", "documents_published_at"); + await queryInterface.removeIndex("documents", "documents_team_id"); + }, +};