Skip to content

Open-source status page, incident response and uptime monitoring

chore: add combobox to regions (#119)

Maximilian Kaske49106c9abaf0
diff --git a/apps/web/src/app/api/checker/cron/_cron.ts b/apps/web/src/app/api/checker/cron/_cron.ts
index e14e380c0..2b58fa520 100644
--- a/apps/web/src/app/api/checker/cron/_cron.ts
+++ b/apps/web/src/app/api/checker/cron/_cron.ts
@@ -1,10 +1,11 @@
import { Client } from "@upstash/qstash/cloudflare";
-import type { z } from "zod";
+import { z } from "zod";
import { and, db, eq } from "@openstatus/db";
import {
monitor,
monitorsToPages,
+ RegionEnum,
selectMonitorSchema,
} from "@openstatus/db/src/schema";
import { availableRegions } from "@openstatus/tinybird";
@@ -14,6 +15,9 @@ import type { payloadSchema } from "../schema";
const periodicityAvailable = selectMonitorSchema.pick({ periodicity: true });
+// FIXME: do coerce in zod instead
+const currentRegions = z.string().transform((val) => val.split(","));
+
const DEFAULT_URL = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";
@@ -48,7 +52,8 @@ export const cron = async ({
.where(eq(monitorsToPages.monitorId, row.id))
.all();
- for (const region of availableRegions) {
+ const allMonitorsRegions = currentRegions.parse(row.regions);
+ if (allMonitorsRegions.length === 0) {
const payload: z.infer<typeof payloadSchema> = {
workspaceId: String(row.workspaceId),
monitorId: String(row.id),
@@ -59,11 +64,27 @@ export const cron = async ({
// TODO: fetch + try - catch + retry once
const result = c.publishJSON({
- url: `${DEFAULT_URL}/api/checker/regions/${region}`,
+ url: `${DEFAULT_URL}/api/checker/regions/random`,
body: payload,
- delay: Math.random() * 180,
+ delay: Math.random() * 90,
});
allResult.push(result);
+ } else {
+ for (const region of allMonitorsRegions) {
+ const payload: z.infer<typeof payloadSchema> = {
+ workspaceId: String(row.workspaceId),
+ monitorId: String(row.id),
+ url: row.url,
+ cronTimestamp: timestamp,
+ pageIds: allPages.map((p) => String(p.pageId)),
+ };
+
+ const result = c.publishJSON({
+ url: `${DEFAULT_URL}/api/checker/regions/${region}`,
+ body: payload,
+ });
+ allResult.push(result);
+ }
}
}
// our first legacy monitor
@@ -82,7 +103,7 @@ export const cron = async ({
const result = c.publishJSON({
url: `${DEFAULT_URL}/api/checker/regions/${region}`,
body: payload,
- delay: Math.random() * 180,
+ delay: Math.random() * 90,
});
allResult.push(result);
}
diff --git a/apps/web/src/app/api/checker/regions/_checker.ts b/apps/web/src/app/api/checker/regions/_checker.ts
index 679c30c71..8529ee960 100644
--- a/apps/web/src/app/api/checker/regions/_checker.ts
+++ b/apps/web/src/app/api/checker/regions/_checker.ts
@@ -86,7 +86,7 @@ export const checker = async (request: Request, region: string) => {
await monitor(res, result.data, region, latency);
} catch (e) {
// if on the third retry we still get an error, we should report it
- if (request.headers.get("Upstash-Retried") === "3") {
+ if (request.headers.get("Upstash-Retried") === "2") {
await monitor(
{ status: 500, text: () => Promise.resolve(`${e}`) },
result.data,
diff --git a/apps/web/src/app/api/checker/regions/random/route.ts b/apps/web/src/app/api/checker/regions/random/route.ts
new file mode 100644
index 000000000..bf05a27b4
--- /dev/null
+++ b/apps/web/src/app/api/checker/regions/random/route.ts
@@ -0,0 +1,17 @@
+import { NextResponse } from "next/server";
+
+import { checker } from "../_checker";
+
+export const runtime = "edge";
+export const preferredRegion = "auto";
+export const dynamic = "force-dynamic";
+// Fix is a random region let's figure where does vercel push it
+
+export async function POST(request: Request) {
+ const region = process.env.VERCEL_REGION;
+ if (!region) {
+ throw new Error("No region");
+ }
+ await checker(request, region);
+ return NextResponse.json({ success: true });
+}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
index ead47dd05..9f8cd737d 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
@@ -2,7 +2,7 @@
import * as React from "react";
import Link from "next/link";
-import { usePathname, useRouter } from "next/navigation";
+import { useRouter } from "next/navigation";
import { MoreVertical } from "lucide-react";
import type * as z from "zod";
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
index ec9b7ce4e..963d60c25 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
@@ -57,7 +57,7 @@ export default async function MonitorPage({
</dd>
</div>
<div className="flex min-w-0 items-center justify-between gap-3">
- <dt>Periodicity</dt>
+ <dt>Frequency</dt>
<dd className="font-mono">{monitor.periodicity}</dd>
</div>
<div className="flex min-w-0 items-center justify-between gap-3">
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
index 56a244c77..c95c8a1ce 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
@@ -14,9 +14,6 @@ import { EmptyState } from "./_components/empty-state";
const limit = allPlans.free.limits["status-pages"];
-// export const revalidate = 300; // revalidate this page every 5 minutes
-export const dynamic = "force-dynamic";
-
export default async function Page({
params,
}: {
diff --git a/apps/web/src/components/forms/montitor-form.tsx b/apps/web/src/components/forms/montitor-form.tsx
index f6093b717..7c0d0beb4 100644
--- a/apps/web/src/components/forms/montitor-form.tsx
+++ b/apps/web/src/components/forms/montitor-form.tsx
@@ -2,6 +2,7 @@
import * as React from "react";
import { zodResolver } from "@hookform/resolvers/zod";
+import { Check, ChevronsUpDown } from "lucide-react";
import { useForm } from "react-hook-form";
import type * as z from "zod";
@@ -11,6 +12,14 @@ import {
} from "@openstatus/db/src/schema";
import { allPlans } from "@openstatus/plans";
+import { Button } from "@/components/ui/button";
+import {
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+} from "@/components/ui/command";
import {
Form,
FormControl,
@@ -21,6 +30,11 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
import {
Select,
SelectContent,
@@ -29,6 +43,8 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
+import { regionsDict } from "@/data/regions-dictionary";
+import { cn } from "@/lib/utils";
const limit = allPlans.free.limits.periodicity;
const cronJobs = [
@@ -39,16 +55,14 @@ const cronJobs = [
{ value: "1h", label: "1 hour" },
] as const;
-type Schema = z.infer<typeof insertMonitorSchema>;
-
interface Props {
id: string;
- defaultValues?: Schema;
- onSubmit: (values: Schema) => Promise<void>;
+ defaultValues?: z.infer<typeof insertMonitorSchema>;
+ onSubmit: (values: z.infer<typeof insertMonitorSchema>) => Promise<void>;
}
export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
- const form = useForm<Schema>({
+ const form = useForm<z.infer<typeof insertMonitorSchema>>({
resolver: zodResolver(insertMonitorSchema), // too much - we should only validate the values we ask inside of the form!
defaultValues: {
url: defaultValues?.url || "",
@@ -57,6 +71,7 @@ export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
periodicity: defaultValues?.periodicity || undefined,
active: defaultValues?.active || true,
id: defaultValues?.id || undefined,
+ regions: defaultValues?.regions || [],
},
});
@@ -134,12 +149,78 @@ export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
</FormItem>
)}
/>
+ <FormField
+ control={form.control}
+ name="regions"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Regions</FormLabel>
+ <Popover>
+ <PopoverTrigger asChild>
+ <FormControl>
+ <Button
+ variant="outline"
+ role="combobox"
+ className={cn(
+ "w-full justify-between",
+ !field.value && "text-muted-foreground",
+ )}
+ >
+ {/* This is a hotfix */}
+ {field.value?.length === 1 && field.value[0].length > 0
+ ? regionsDict[
+ field.value[0] as keyof typeof regionsDict
+ ].location
+ : "Select region"}
+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ </Button>
+ </FormControl>
+ </PopoverTrigger>
+ <PopoverContent className="w-full p-0">
+ <Command>
+ <CommandInput placeholder="Select a region..." />
+ <CommandEmpty>No regions found.</CommandEmpty>
+ <CommandGroup>
+ {Object.keys(regionsDict).map((region) => {
+ const { code, location } =
+ regionsDict[region as keyof typeof regionsDict];
+ const isSelected = field.value?.includes(code);
+ return (
+ <CommandItem
+ value={code}
+ key={code}
+ onSelect={() => {
+ form.setValue("regions", [code]); // TODO: allow more than one to be selected in the future
+ }}
+ >
+ <Check
+ className={cn(
+ "mr-2 h-4 w-4",
+ isSelected ? "opacity-100" : "opacity-0",
+ )}
+ />
+ {location}
+ </CommandItem>
+ );
+ })}
+ </CommandGroup>
+ </Command>
+ </PopoverContent>
+ </Popover>
+ <FormDescription>
+ Select the regions you want to monitor, or leave it blank for
+ randomly picked regions.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
<FormField
control={form.control}
name="periodicity"
render={({ field }) => (
<FormItem>
- <FormLabel>Periodicity</FormLabel>
+ <FormLabel>Frequency</FormLabel>
<Select
onValueChange={(value) =>
field.onChange(periodicityEnum.parse(value))
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 7382c6b47..6e6286136 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -66,12 +66,14 @@ export const monitorRouter = createTRPCRouter({
message: "You reached your cron job limits.",
});
}
+ const { regions, ...data } = opts.input.data;
const newMonitor = await opts.ctx.db
.insert(monitor)
.values({
- ...opts.input.data,
+ ...data,
workspaceId: currentWorkspace.id,
+ regions: regions?.join(","),
})
.returning()
.get();
@@ -184,10 +186,11 @@ export const monitorRouter = createTRPCRouter({
message: "You reached your cron job limits.",
});
}
-
+ console.log(opts.input.regions?.join(","));
+ const { regions, ...data } = opts.input;
await opts.ctx.db
.update(monitor)
- .set(opts.input)
+ .set({ ...data, regions: regions?.join(",") })
.where(eq(monitor.id, opts.input.id))
.returning()
.get();
diff --git a/packages/db/drizzle/0000_lively_master_chief.sql b/packages/db/drizzle/0000_lively_master_chief.sql
index 3535d2666..4f5c1e653 100644
--- a/packages/db/drizzle/0000_lively_master_chief.sql
+++ b/packages/db/drizzle/0000_lively_master_chief.sql
@@ -1,20 +1,3 @@
-DROP TABLE IF EXISTS `incident`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `incident_update`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `monitors_to_pages`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `monitor`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `page`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `users_to_workspaces`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `user`;
---> statement-breakpoint
-DROP TABLE IF EXISTS `workspace`;
---> statement-breakpoint
-
CREATE TABLE `incident` (
`id` integer PRIMARY KEY NOT NULL,
`status` text(2) NOT NULL,
diff --git a/packages/db/drizzle/0001_brainy_beast.sql b/packages/db/drizzle/0001_brainy_beast.sql
new file mode 100644
index 000000000..ed551a6c2
--- /dev/null
+++ b/packages/db/drizzle/0001_brainy_beast.sql
@@ -0,0 +1,2 @@
+ALTER TABLE monitor ADD `regions` text DEFAULT '' NOT NULL;
+
diff --git a/packages/db/drizzle/meta/0001_snapshot.json b/packages/db/drizzle/meta/0001_snapshot.json
new file mode 100644
index 000000000..4107f857d
--- /dev/null
+++ b/packages/db/drizzle/meta/0001_snapshot.json
@@ -0,0 +1,564 @@
+{
+ "version": "5",
+ "dialect": "sqlite",
+ "id": "762acc59-e72a-4ca4-b3fa-2cfd65cdf49a",
+ "prevId": "41c8003d-9f2a-4d3e-9e11-b3d4076fe395",
+ "tables": {
+ "incident": {
+ "name": "incident",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text(2)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "page_id": {
+ "name": "page_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "incident_page_id_page_id_fk": {
+ "name": "incident_page_id_page_id_fk",
+ "tableFrom": "incident",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "incident_update": {
+ "name": "incident_update",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "uuid": {
+ "name": "uuid",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_date": {
+ "name": "incident_date",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "incident_update_uuid_unique": {
+ "name": "incident_update_uuid_unique",
+ "columns": [
+ "uuid"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "incident_update_incident_id_incident_id_fk": {
+ "name": "incident_update_incident_id_incident_id_fk",
+ "tableFrom": "incident_update",
+ "tableTo": "incident",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "page": {
+ "name": "page",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "custom_domain": {
+ "name": "custom_domain",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "published": {
+ "name": "published",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "page_slug_unique": {
+ "name": "page_slug_unique",
+ "columns": [
+ "slug"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "page_workspace_id_workspace_id_fk": {
+ "name": "page_workspace_id_workspace_id_fk",
+ "tableFrom": "page",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitor": {
+ "name": "monitor",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "job_type": {
+ "name": "job_type",
+ "type": "text(3)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "periodicity": {
+ "name": "periodicity",
+ "type": "text(6)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text(2)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'inactive'"
+ },
+ "active": {
+ "name": "active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "regions": {
+ "name": "regions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "url": {
+ "name": "url",
+ "type": "text(512)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitor_workspace_id_workspace_id_fk": {
+ "name": "monitor_workspace_id_workspace_id_fk",
+ "tableFrom": "monitor",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitors_to_pages": {
+ "name": "monitors_to_pages",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitors_to_pages_monitor_id_monitor_id_fk": {
+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",
+ "tableFrom": "monitors_to_pages",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "monitors_to_pages_page_id_page_id_fk": {
+ "name": "monitors_to_pages_page_id_page_id_fk",
+ "tableFrom": "monitors_to_pages",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "monitors_to_pages_monitor_id_page_id_pk": {
+ "columns": [
+ "monitor_id",
+ "page_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "user": {
+ "name": "user",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tenant_id": {
+ "name": "tenant_id",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "user_tenant_id_unique": {
+ "name": "user_tenant_id_unique",
+ "columns": [
+ "tenant_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "users_to_workspaces": {
+ "name": "users_to_workspaces",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "users_to_workspaces_user_id_user_id_fk": {
+ "name": "users_to_workspaces_user_id_user_id_fk",
+ "tableFrom": "users_to_workspaces",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "users_to_workspaces_workspace_id_workspace_id_fk": {
+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",
+ "tableFrom": "users_to_workspaces",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "users_to_workspaces_user_id_workspace_id_pk": {
+ "columns": [
+ "user_id",
+ "workspace_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "workspace": {
+ "name": "workspace",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "stripe_id": {
+ "name": "stripe_id",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "workspace_slug_unique": {
+ "name": "workspace_slug_unique",
+ "columns": [
+ "slug"
+ ],
+ "isUnique": true
+ },
+ "workspace_stripe_id_unique": {
+ "name": "workspace_stripe_id_unique",
+ "columns": [
+ "stripe_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ }
+}
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json
index 958a1ba50..14e087071 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -8,6 +8,13 @@
"when": 1690309905039,
"tag": "0000_lively_master_chief",
"breakpoints": true
+ },
+ {
+ "idx": 1,
+ "version": "5",
+ "when": 1690892003254,
+ "tag": "0001_brainy_beast",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/packages/db/src/migrate.mts b/packages/db/src/migrate.mts
index 3941be8e5..6262327de 100644
--- a/packages/db/src/migrate.mts
+++ b/packages/db/src/migrate.mts
@@ -10,7 +10,6 @@ async function main() {
const db = drizzle(
createClient({ url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN }),
);
-
console.log("Running migrations");
await migrate(db, { migrationsFolder: "drizzle" });
diff --git a/packages/db/src/schema/monitor.ts b/packages/db/src/schema/monitor.ts
index aaedc1d0c..dfabe0a8d 100644
--- a/packages/db/src/schema/monitor.ts
+++ b/packages/db/src/schema/monitor.ts
@@ -11,6 +11,29 @@ import { z } from "zod";
import { page } from "./page";
import { workspace } from "./workspace";
+export const availableRegions = [
+ "arn1",
+ "bom1",
+ "cdg1",
+ "cle1",
+ "cpt1",
+ "dub1",
+ "fra1",
+ "gru1",
+ "hkg1",
+ "hnd1",
+ "iad1",
+ "icn1",
+ "kix1",
+ "lhr1",
+ "pdx1",
+ "sfo1",
+ "sin1",
+ "syd1",
+] as const;
+
+export const RegionEnum = z.enum(availableRegions);
+
export const monitor = sqliteTable("monitor", {
id: integer("id").primaryKey(),
jobType: text("job_type", ["website", "cron", "other"])
@@ -22,6 +45,8 @@ export const monitor = sqliteTable("monitor", {
status: text("status", ["active", "inactive"]).default("inactive").notNull(),
active: integer("active", { mode: "boolean" }).default(false),
+ regions: text("regions").default("").notNull(),
+
url: text("url", { length: 512 }).notNull(),
name: text("name", { length: 256 }).default("").notNull(),
@@ -88,6 +113,7 @@ export const insertMonitorSchema = createInsertSchema(monitor, {
url: z.string().url(),
status: z.enum(["active", "inactive"]).default("inactive"),
active: z.boolean().default(false),
+ regions: z.array(RegionEnum).default([]).optional(),
});
// Schema for selecting a Monitor - can be used to validate API responses
@@ -96,6 +122,9 @@ export const selectMonitorSchema = createSelectSchema(monitor, {
status: z.enum(["active", "inactive"]).default("inactive"),
jobType: z.enum(["website", "cron", "other"]).default("other"),
active: z.boolean().default(false),
+ regions: z
+ .preprocess((val) => String(val).split(","), z.array(RegionEnum))
+ .default([]),
});
export const allMonitorsSchema = z.array(selectMonitorSchema);