Files
Checkmate/server/src/db/migration/0012_migrateDockerMonitorUrls.ts
T

36 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-08-28 14:42:46 -07:00
import { MonitorModel } from "../../domain/monitors/monitor.model.js";
import type { ILogger } from "@/utils/logger.js";
/**
* Rewrite docker monitor urls from the old container-name semantics to host urls.
*
* The old docker provider interpreted monitor.url as a container name/ID and only
* ever talked to the local socket, so every pre-existing docker monitor's host is
* definitionally unix:///var/run/docker.sock. The container name is preserved in
2026-09-04 14:19:11 -07:00
* the description. Urls already in host form (unix:// or an absolute socket
* path) are left untouched, which makes the migration idempotent.
2026-08-28 14:42:46 -07:00
*/
export async function migrateDockerMonitorUrls(logger: ILogger): Promise<void> {
const SERVICE_NAME = "Migration:MigrateDockerMonitorUrls";
try {
logger.info({ service: SERVICE_NAME, message: "Starting docker monitor url migration" });
2026-09-04 14:19:11 -07:00
const result = await MonitorModel.updateMany({ type: "docker", url: { $not: /^(unix:\/\/|\/)/ } }, [
2026-08-28 14:42:46 -07:00
{
$set: {
description: {
$concat: [{ $ifNull: ["$description", ""] }, " (was container: ", "$url", ")"],
},
url: "unix:///var/run/docker.sock",
},
},
]);
logger.info({ service: SERVICE_NAME, message: `Migrated ${result.modifiedCount} docker monitors to host urls` });
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.error({ service: SERVICE_NAME, message: `Error migrating docker monitor urls: ${errorMessage}` });
throw error;
}
}