From 958ff0f3bf038e5b6bf0ba0ae5a7d0b236080cca Mon Sep 17 00:00:00 2001 From: Eric Mc Sween <5454374+emcsween@users.noreply.github.com> Date: Mon, 14 Apr 2025 07:55:23 -0400 Subject: [PATCH] Merge pull request #24847 from overleaf/em-chunks-index Include closed chunks in active chunks index GitOrigin-RevId: ff75959737908afa72cee2c2784abb476c115e80 --- ...250411200550_active_chunk_index_update.mjs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 services/web/migrations/20250411200550_active_chunk_index_update.mjs diff --git a/services/web/migrations/20250411200550_active_chunk_index_update.mjs b/services/web/migrations/20250411200550_active_chunk_index_update.mjs new file mode 100644 index 0000000000..23893a4836 --- /dev/null +++ b/services/web/migrations/20250411200550_active_chunk_index_update.mjs @@ -0,0 +1,41 @@ +import Helpers from './lib/helpers.mjs' + +const tags = ['server-ce', 'server-pro', 'saas'] + +const oldIndex = { + name: 'projectId_1_startVersion_1', + key: { + projectId: 1, + startVersion: 1, + }, + unique: true, + partialFilterExpression: { state: 'active' }, +} + +const newIndex = { + name: 'projectId_1_startVersion_1_v2', + key: { + projectId: 1, + startVersion: 1, + }, + unique: true, + partialFilterExpression: { state: { $in: ['active', 'closed'] } }, +} + +const migrate = async client => { + const { db } = client + await Helpers.addIndexesToCollection(db.projectHistoryChunks, [newIndex]) + await Helpers.dropIndexesFromCollection(db.projectHistoryChunks, [oldIndex]) +} + +const rollback = async client => { + const { db } = client + await Helpers.addIndexesToCollection(db.projectHistoryChunks, [oldIndex]) + await Helpers.dropIndexesFromCollection(db.projectHistoryChunks, [newIndex]) +} + +export default { + tags, + migrate, + rollback, +}