Migration for "notificationsPreferences" collection (#29446)

* Implement notifications preferences model

* NotificationPreferences class

* remove index performance tests

* move to unit tests

* use zod

* saving multiple preference values

* set unique:true

* throw error if preferences can't be parsed

* use z.infer

* strict schema when saving preferences

* fix: update notifPreferenceKey type to only contain key values

---------

Co-authored-by: Domagoj Kriskovic <dom.kriskovic@overleaf.com>
GitOrigin-RevId: 20cf3799c91e6a890ab6217667594d181237c791
This commit is contained in:
Jimmy Domagala-Tang
2025-11-18 09:19:47 -08:00
committed by Copybot
parent 06a1fc32ec
commit ff987aa433
2 changed files with 37 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ const db = {
migrations: internalDb.collection('migrations'),
notifications: internalDb.collection('notifications'),
emailNotifications: internalDb.collection('emailNotifications'),
notificationsPreferences: internalDb.collection('notificationsPreferences'),
oauthAccessTokens: internalDb.collection('oauthAccessTokens'),
oauthApplications: internalDb.collection('oauthApplications'),
oauthAuthorizationCodes: internalDb.collection('oauthAuthorizationCodes'),

View File

@@ -0,0 +1,36 @@
import Helpers from './lib/helpers.mjs'
import { getCollectionInternal } from './lib/mongodb.mjs'
const tags = ['server-ce', 'server-pro', 'saas']
const indexes = [
{
// compound index for querying both global (project_id: null) and project-specific notification preferences
key: {
user_id: 1,
project_id: 1,
},
unique: true,
name: 'user_id_1_project_id_1',
},
]
const migrate = async () => {
const notificationsPreferences = await getCollectionInternal(
'notificationsPreferences'
)
await Helpers.addIndexesToCollection(notificationsPreferences, indexes)
}
const rollback = async () => {
const notificationsPreferences = await getCollectionInternal(
'notificationsPreferences'
)
await Helpers.dropIndexesFromCollection(notificationsPreferences, indexes)
}
export default {
tags,
migrate,
rollback,
}