Skip to content

Commit 652d231

Browse files
committed
add migration for statusWindowThreshold
1 parent e7006a4 commit 652d231

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

server/src/db/mongo/MongoDB.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mongoose from "mongoose";
22
import AppSettings from "../models/AppSettings.js";
3-
3+
import { runMigrations } from "./migration/index.js";
44
class MongoDB {
55
static SERVICE_NAME = "MongoDB";
66

@@ -65,6 +65,8 @@ class MongoDB {
6565
service: this.SERVICE_NAME,
6666
method: "connect",
6767
});
68+
69+
await runMigrations();
6870
} catch (error) {
6971
this.logger.error({
7072
message: error.message,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Monitor from "../../models/Monitor.js";
2+
async function migrateStatusWindowThreshold() {
3+
try {
4+
const monitors = await Monitor.find({ statusWindowThreshold: { $lt: 1 } });
5+
for (const monitor of monitors) {
6+
monitor.statusWindowThreshold = monitor.statusWindowThreshold * 100;
7+
await monitor.save();
8+
console.log(`Migrated monitor ${monitor._id}: statusWindowThreshold set to ${monitor.statusWindowThreshold}`);
9+
}
10+
console.log("StatusWindowThreshold migration complete.");
11+
return true;
12+
} catch (err) {
13+
console.error("Migration error:", err);
14+
return false;
15+
}
16+
}
17+
18+
export { migrateStatusWindowThreshold };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js";
2+
3+
const runMigrations = async () => {
4+
await migrateStatusWindowThreshold();
5+
};
6+
7+
export { runMigrations };

0 commit comments

Comments
 (0)