Quellcode durchsuchen

Add migration script for creating emailNotifications collection (#28972)

GitOrigin-RevId: 73845e7e7dfe61f0a7ca19f4f8be94e6b41594c5
Domagoj Kriskovic vor 10 Monaten
Ursprung
Commit
387ef81a31

+ 42 - 0
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,
+}