add db migration for proxy mode inherit

This commit is contained in:
Alex Holliday committed 2026-08-20 14:31:23 -07:00
1 parent ede93add64
commit 637bb5cca9
2 files changed
+29

No files matched your search

@@ -0,0 +1,27 @@
import { MonitorModel } from "../../domain/monitors/monitor.model.js";
import type { ILogger } from "@/utils/logger.js";
/**
* Backfill proxyMode on monitors created before the field existed.
*
* Mongoose defaults only apply to new documents, and monitorResponseSchema
* requires proxyMode on every monitor read.
*/
export async function backfillMonitorProxyMode(logger: ILogger): Promise<void> {
const SERVICE_NAME = "Migration:BackfillMonitorProxyMode";
try {
logger.info({ service: SERVICE_NAME, message: "Starting proxyMode backfill" });
const result = await MonitorModel.updateMany({ proxyMode: { $exists: false } }, { $set: { proxyMode: "inherit" } });
logger.info({
service: SERVICE_NAME,
message: `Backfilled proxyMode on ${result.modifiedCount} monitors`,
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error({ service: SERVICE_NAME, message: `Error backfilling proxyMode: ${errorMessage}` });
throw error;
}
}
+2
View File
@@ -9,6 +9,7 @@ import { migrateMaintenanceWindowMonitorIdToArray } from "./0007_migrateMaintena
import { backfillMonitorLastEvaluatedAt } from "./0008_backfillMonitorLastEvaluatedAt.js";
import { recomputeResponseTimeFromTimings } from "./0009_recomputeResponseTimeFromTimings.js";
import { slimRecentChecks } from "./0010_slimRecentChecks.js";
import { backfillMonitorProxyMode } from "./0011_backfillMonitorProxyMode.js";
import type { ILogger } from "@/utils/logger.js";
type MigrationEntry = {
@@ -27,6 +28,7 @@ const migrations: MigrationEntry[] = [
{ name: "0008_backfillMonitorLastEvaluatedAt", execute: backfillMonitorLastEvaluatedAt },
{ name: "0009_recomputeResponseTimeFromTimings", execute: recomputeResponseTimeFromTimings },
{ name: "0010_slimRecentChecks", execute: slimRecentChecks },
{ name: "0011_backfillMonitorProxyMode", execute: backfillMonitorProxyMode },
];
const runMigrations = async (logger: ILogger) => {