drop jobs in migration
This commit is contained in:
1 parent
306f2a60a2
commit
2d68e96782
1 file changed
+15
@@ -1,6 +1,9 @@
|
||||
import mongoose from "mongoose";
|
||||
import { MonitorModel } from "../../domain/monitors/monitor.model.js";
|
||||
import { logger } from "@/utils/logger.js";
|
||||
|
||||
const JOBS_COLLECTION = "jobs";
|
||||
|
||||
/**
|
||||
* Backfill lastEvaluatedAt on monitors created before the lastEvaluatedAt existed.
|
||||
*
|
||||
@@ -10,6 +13,18 @@ export async function backfillMonitorLastEvaluatedAt(): Promise<void> {
|
||||
const SERVICE_NAME = "Migration:BackfillMonitorLastEvaluatedAt";
|
||||
|
||||
try {
|
||||
// Drop the legacy jobs collection first. The old super-simple-scheduler persisted jobs to the
|
||||
// same "jobs" collection the new db-queue uses, so any leftover rows carry an incompatible schema.
|
||||
// Migrations run before syncIndexes(), so the new Job indexes are rebuilt right after this drop.
|
||||
const db = mongoose.connection.db;
|
||||
if (db) {
|
||||
const existing = await db.listCollections({ name: JOBS_COLLECTION }).toArray();
|
||||
if (existing.length > 0) {
|
||||
await db.collection(JOBS_COLLECTION).drop();
|
||||
logger.info({ service: SERVICE_NAME, message: `Dropped legacy "${JOBS_COLLECTION}" collection` });
|
||||
}
|
||||
}
|
||||
|
||||
logger.info({ service: SERVICE_NAME, message: "Starting lastEvaluatedAt backfill" });
|
||||
|
||||
const result = await MonitorModel.updateMany({ lastEvaluatedAt: { $exists: false } }, { $set: { lastEvaluatedAt: Date.now() } });
|
||||
|
||||
Reference in new issue
Block a user