Files
overleaf-cep/tools/migrations/20260808093000_create_studentVerifications_indexes.mjs
T
Tim Down c3d962c075 Add the SheerID student verification module (#36704)
GitOrigin-RevId: a3673c09e185c8f857d5da3e706fa9a310fba6d4
2026-09-17 12:07:32 +00:00

60 lines
1.8 KiB
JavaScript

import Helpers from './lib/helpers.mjs'
import { getCollectionInternal } from './lib/mongodb.mjs'
const tags = ['saas']
// Keep in sync with the indexes declared on the model
// (services/web/app/src/models/StudentVerification.mjs): Mongoose runs with
// autoIndex: false, so nothing creates these automatically.
const indexes = [
{
// Every lookup of a single verification is by this id (status polling, the
// webhook, and the mock outcome controls).
key: { verificationId: 1 },
unique: true,
name: 'verificationId_1',
},
{
// The purchase gate: the user's latest unexpired SUCCESS verification.
key: { userId: 1, status: 1, createdAt: -1 },
name: 'userId_1_status_1_createdAt_-1',
},
{
// Retention: records carry their own `expires` date, so the TTL monitor
// deletes each one at the time stored on it rather than after a fixed
// interval.
key: { expires: 1 },
expireAfterSeconds: 0,
name: 'expires_1',
},
{
// The reconciliation poller
// (modules/student-verification/scripts/reconcile_student_verifications.mjs)
// sweeps pending records by refresh staleness, with no userId to narrow
// on, so the {userId, status, createdAt} index cannot serve it and the DB
// runs with notablescan.
key: { status: 1, lastRefreshedAt: 1 },
name: 'status_1_lastRefreshedAt_1',
},
]
const migrate = async () => {
const studentVerifications = await getCollectionInternal(
'studentVerifications'
)
await Helpers.addIndexesToCollection(studentVerifications, indexes)
}
const rollback = async () => {
const studentVerifications = await getCollectionInternal(
'studentVerifications'
)
await Helpers.dropIndexesFromCollection(studentVerifications, indexes)
}
export default {
tags,
migrate,
rollback,
}