Files
overleaf-cep/tools/migrations/20260604174200_zotero_libraryReferences_sources.mjs
T
Eric Mc Sween 528e587038 Merge pull request #35377 from overleaf/em-change-library-mongo-cluster
Add auxiliary Mongo cluster support for library collections

GitOrigin-RevId: 1cfdbe4bbeb6c95f1158834ae60a4e34bef7bb87
2026-09-17 11:26:00 +00:00

43 lines
1.1 KiB
JavaScript

import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
import Helpers from './lib/helpers.mjs'
const tags = ['saas', 'auxiliary']
const indexes = [
{
key: {
userId: 1,
'sources.zotero.libraryType': 1,
'sources.zotero.libraryId': 1,
'sources.zotero.itemKey': 1,
},
name: 'userId_1_sources.zotero.libraryType_1_sources.zotero.libraryId_1_sources.zotero.itemKey_1',
unique: true,
// Not `sparse`: userId is always present, so a sparse compound index would
// include every doc and collide native entries on (userId, null, null,
// null). Scope uniqueness to Zotero-linked docs only.
partialFilterExpression: { 'sources.zotero.itemKey': { $exists: true } },
},
]
const migrate = async client => {
const { db } = client
await batchedUpdate(
db.libraryReferences,
{ sources: { $exists: false } },
{ $set: { sources: {} } }
)
await Helpers.addIndexesToCollection(db.libraryReferences, indexes)
}
const rollback = async client => {
const { db } = client
await Helpers.dropIndexesFromCollection(db.libraryReferences, indexes)
}
export default {
tags,
migrate,
rollback,
}