Files
overleaf-cep/tools/migrations/20260722120000_create_libraryReferences_trashedAt_indexes.mjs
T
Domagoj KriskovicandCopilot Autofix powered by AI 1ef6360fb9 comment typo
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitOrigin-RevId: abb0bfda774dc278ae3256ee5a461240f5511461
2026-09-17 11:38:59 +00:00

37 lines
950 B
JavaScript

import Helpers from './lib/helpers.mjs'
const tags = ['auxiliary']
// Two partial indexes (docs without trashedAt are not indexed) supporting the
// soft-delete (trash) feature
// - userId_1_trashedAt_1__id_1 serves the per-user trash listing/search,
// - trashedAt_1 serves the daily expiry cron's cross-user scan.
const newIndexes = [
{
key: { userId: 1, trashedAt: 1, _id: 1 },
name: 'userId_1_trashedAt_1__id_1',
partialFilterExpression: { trashedAt: { $exists: true } },
},
{
key: { trashedAt: 1 },
name: 'trashedAt_1',
partialFilterExpression: { trashedAt: { $exists: true } },
},
]
const migrate = async client => {
const { db } = client
await Helpers.addIndexesToCollection(db.libraryReferences, newIndexes)
}
const rollback = async client => {
const { db } = client
await Helpers.dropIndexesFromCollection(db.libraryReferences, newIndexes)
}
export default {
tags,
migrate,
rollback,
}