From 387ef81a31fdb9648bae263ce4127284c5453d59 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Fri, 17 Oct 2025 10:57:23 +0200 Subject: [PATCH] Add migration script for creating emailNotifications collection (#28972) GitOrigin-RevId: 73845e7e7dfe61f0a7ca19f4f8be94e6b41594c5 --- ...8_create_emailNotifications_collection.mjs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/migrations/20251016112728_create_emailNotifications_collection.mjs diff --git a/tools/migrations/20251016112728_create_emailNotifications_collection.mjs b/tools/migrations/20251016112728_create_emailNotifications_collection.mjs new file mode 100644 index 0000000000..2ea0904981 --- /dev/null +++ b/tools/migrations/20251016112728_create_emailNotifications_collection.mjs @@ -0,0 +1,42 @@ +/* eslint-disable no-unused-vars */ + +import Helpers from './lib/helpers.mjs' +import { getCollectionInternal } from './lib/mongodb.mjs' + +const tags = ['server-pro', 'saas'] + +const indexes = [ + { + key: { + scheduledAt: 1, + }, + name: 'scheduledAt_1', + expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours + }, + { + // used for querying notifications to find possible duplicates + unique: false, + key: { + user_id: 1, + recipient_id: 1, + project_id: 1, + }, + name: 'user_id_1_recipient_id_1_project_id_1', + }, +] + +const migrate = async () => { + const emailNotifications = await getCollectionInternal('emailNotifications') + await Helpers.addIndexesToCollection(emailNotifications, indexes) +} + +const rollback = async () => { + const emailNotifications = await getCollectionInternal('emailNotifications') + await Helpers.dropIndexesFromCollection(emailNotifications, indexes) +} + +export default { + tags, + migrate, + rollback, +}