Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.8 kB ยท 60 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { z } from "zod";
import { db, eq, schema } from "../src";import { selectMonitorSchema } from "../src/schema";import type { monitorRegionSchema } from "../src/schema/constants";
const rawMonitors = await db.select().from(schema.monitor);
const monitors = z.array(selectMonitorSchema).parse(rawMonitors);for (const monitor of monitors) { const regions = monitor.regions.slice(); // Asia Pacific updateRegion("hkg", "sin", regions);
// North America updateRegion("atl", "dfw", regions); updateRegion("mia", "dfw", regions); updateRegion("gdl", "dfw", regions); updateRegion("qro", "dfw", regions); updateRegion("bos", "ewr", regions); updateRegion("phx", "lax", regions); updateRegion("sea", "sjc", regions); updateRegion("yul", "yyz", regions); updateRegion("den", "dfw", regions);
// Europe updateRegion("waw", "ams", regions); updateRegion("mad", "cdg", regions); updateRegion("otp", "fra", regions);
// South America updateRegion("bog", "gru", regions); updateRegion("gig", "gru", regions); updateRegion("scl", "gru", regions); updateRegion("eze", "gru", regions); const newRegions = regions.join(","); // console.log("new regions:",newRegions) await db .update(schema.monitor) .set({ regions: newRegions }) .where(eq(schema.monitor.id, monitor.id)) .execute();}
export function updateRegion( oldRegion: z.infer<typeof monitorRegionSchema>, newRegion: z.infer<typeof monitorRegionSchema>, regions: z.infer<typeof monitorRegionSchema>[],) { const regionIndex = regions.indexOf(oldRegion); if (regionIndex !== -1) { const newRegionIndex = regions.indexOf(newRegion); if (newRegionIndex === -1) { regions[regionIndex] = newRegion; } if (newRegionIndex !== -1) { regions.splice(regionIndex, 1); } }}