Add migration for libraryReferences trashedAt indexes

GitOrigin-RevId: 4a850c11560df3ae3053fbc66048b083e750b8d3
This commit is contained in:
Domagoj Kriskovic
2026-09-17 11:38:56 +00:00
committed by Copybot
parent e814176bba
commit a71c8c24d9
@@ -0,0 +1,36 @@
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
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,
}