fix migraiton lint errors
This commit is contained in:
1 parent
120c5cd472
commit
1a504a3cd9
4 files changed
+13
-9
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
|
import type { Document, AnyBulkWriteOperation } from "mongodb";
|
||||||
|
|
||||||
const CHECKS_COLLECTION = "checks";
|
const CHECKS_COLLECTION = "checks";
|
||||||
const BACKUP_COLLECTION = "checks_backup";
|
const BACKUP_COLLECTION = "checks_backup";
|
||||||
@@ -85,7 +86,7 @@ const createTimeSeriesCollection = async (backedUp: boolean) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateDocument = (doc: any): boolean => {
|
const validateDocument = (doc: Document): boolean => {
|
||||||
if (!doc.createdAt) {
|
if (!doc.createdAt) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,7 @@ const validateDocument = (doc: any): boolean => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const storeFailedDocument = async (doc: any, reason: string) => {
|
const storeFailedDocument = async (doc: Document, reason: string) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
await db.collection(FAILED_DOCS_COLLECTION).insertOne({
|
await db.collection(FAILED_DOCS_COLLECTION).insertOne({
|
||||||
originalDoc: doc,
|
originalDoc: doc,
|
||||||
@@ -124,8 +125,8 @@ const migrateBackupData = async (backedUp: boolean): Promise<MigrationStats> =>
|
|||||||
stats.totalSource = await source.countDocuments();
|
stats.totalSource = await source.countDocuments();
|
||||||
|
|
||||||
const cursor = source.find().addCursorFlag("noCursorTimeout", true);
|
const cursor = source.find().addCursorFlag("noCursorTimeout", true);
|
||||||
const operations: any[] = [];
|
const operations: AnyBulkWriteOperation<Document>[] = [];
|
||||||
const invalidDocs: any[] = [];
|
const invalidDocs: Document[] = [];
|
||||||
|
|
||||||
while (await cursor.hasNext()) {
|
while (await cursor.hasNext()) {
|
||||||
const doc = await cursor.next();
|
const doc = await cursor.next();
|
||||||
@@ -139,6 +140,7 @@ const migrateBackupData = async (backedUp: boolean): Promise<MigrationStats> =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { _id, monitorId, teamId, type, ...rest } = doc;
|
const { _id, monitorId, teamId, type, ...rest } = doc;
|
||||||
|
void _id;
|
||||||
const metadata = { monitorId, teamId, type };
|
const metadata = { monitorId, teamId, type };
|
||||||
operations.push({ insertOne: { document: { ...rest, metadata } } });
|
operations.push({ insertOne: { document: { ...rest, metadata } } });
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ export async function cleanupDuplicateMonitorStats(): Promise<void> {
|
|||||||
const monitorId = duplicate._id;
|
const monitorId = duplicate._id;
|
||||||
const { ids, updatedAts } = duplicate;
|
const { ids, updatedAts } = duplicate;
|
||||||
|
|
||||||
type DocPair = { id: any; updatedAt: Date };
|
type DocPair = { id: string; updatedAt: Date };
|
||||||
|
|
||||||
// Create array of {id, updatedAt} pairs and sort by updatedAt descending
|
// Create array of {id, updatedAt} pairs and sort by updatedAt descending
|
||||||
const docs: DocPair[] = ids.map((id: any, index: number) => ({
|
const docs: DocPair[] = ids.map((id: string, index: number) => ({
|
||||||
id,
|
id,
|
||||||
updatedAt: updatedAts[index],
|
updatedAt: updatedAts[index],
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ export async function fixInfrastructureThresholds(): Promise<void> {
|
|||||||
const update: Record<string, number> = {};
|
const update: Record<string, number> = {};
|
||||||
|
|
||||||
for (const field of thresholdFields) {
|
for (const field of thresholdFields) {
|
||||||
if ((monitor as any)[field] === 0 || (monitor as any)[field] === 5) {
|
const value = monitor.get(field);
|
||||||
|
if (value === 0 || value === 5) {
|
||||||
update[field] = 100;
|
update[field] = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { cleanupDuplicateMonitorStats } from "./0003_cleanupDuplicateMonitorStat
|
|||||||
import { fixInfrastructureThresholds } from "./0004_fixInfrastructureThresholds.js";
|
import { fixInfrastructureThresholds } from "./0004_fixInfrastructureThresholds.js";
|
||||||
import MigrationModel from "../models/Migration.js";
|
import MigrationModel from "../models/Migration.js";
|
||||||
import { migrateStatusPageTypeToArray } from "./0005_migrateStatusPageTypeToArray.js";
|
import { migrateStatusPageTypeToArray } from "./0005_migrateStatusPageTypeToArray.js";
|
||||||
|
import type { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
type MigrationEntry = {
|
type MigrationEntry = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -18,7 +19,7 @@ const migrations: MigrationEntry[] = [
|
|||||||
{ name: "0005_migrateStatusPageTypeToArray", execute: migrateStatusPageTypeToArray },
|
{ name: "0005_migrateStatusPageTypeToArray", execute: migrateStatusPageTypeToArray },
|
||||||
];
|
];
|
||||||
|
|
||||||
const runMigrations = async (logger?: { info: Function; error: Function }) => {
|
const runMigrations = async (logger?: ILogger) => {
|
||||||
try {
|
try {
|
||||||
logger?.info({ message: "Running migrations", service: "Migrations" });
|
logger?.info({ message: "Running migrations", service: "Migrations" });
|
||||||
for (const migration of migrations) {
|
for (const migration of migrations) {
|
||||||
@@ -45,7 +46,7 @@ const runMigrations = async (logger?: { info: Function; error: Function }) => {
|
|||||||
logger?.info({ message: "Migrations completed", service: "Migrations" });
|
logger?.info({ message: "Migrations completed", service: "Migrations" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = error as Error;
|
const err = error as Error;
|
||||||
logger?.error({ message: "Migration failed", service: "Migrations", details: err?.message, stack: err?.stack });
|
logger?.error({ message: "Migration failed", service: "Migrations", details: { error: err?.message }, stack: err?.stack });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user