Skip to content

Open-source status page, incident response and uptime monitoring

feat: incidents to pages (#375)

Maximilian Kaske591175b6bc66
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx
index 6c14ce24c..7a397e811 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx
@@ -26,6 +26,7 @@ export default async function EditPage({
}
const { id } = search.data;
+ const { workspaceSlug } = params;
const incident = id
? await api.incident.getIncidentById.query({
@@ -34,24 +35,28 @@ export default async function EditPage({
: undefined;
const monitors = await api.monitor.getMonitorsByWorkspace.query({
- workspaceSlug: params.workspaceSlug,
+ workspaceSlug,
});
+ const pages = await api.page.getPagesByWorkspace.query({ workspaceSlug });
+
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
<Header title="Incident" description="Upsert your incident." />
<div className="col-span-full">
<IncidentForm
- workspaceSlug={params.workspaceSlug}
+ workspaceSlug={workspaceSlug}
monitors={monitors}
+ pages={pages}
defaultValues={
incident
? {
...incident,
- workspaceSlug: params.workspaceSlug,
+ workspaceSlug,
monitors: incident?.monitorsToIncidents.map(
({ monitorId }) => monitorId,
),
+ pages: incident?.pagesToIncidents.map(({ pageId }) => pageId),
}
: undefined
}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx
index ba3fcf561..ec3a9e24d 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx
@@ -41,6 +41,9 @@ export default async function IncidentPage({
{incidents?.map((incident, i) => {
const { label, icon } =
statusDict[incident.status as keyof typeof statusDict];
+ const monitors = incident.monitorsToIncidents.map(
+ ({ monitor }) => monitor,
+ );
return (
<li key={i} className="grid gap-2">
<time className="text-muted-foreground pl-3 text-xs">
@@ -71,16 +74,14 @@ export default async function IncidentPage({
]}
>
<div className="grid gap-4">
- <div>
- <p className="text-muted-foreground mb-1.5 text-xs">
- Affected Monitors
- </p>
- <AffectedMonitors
- monitors={incident.monitorsToIncidents.map(
- ({ monitor }) => monitor,
- )}
- />
- </div>
+ {Boolean(monitors.length) ? (
+ <div>
+ <p className="text-muted-foreground mb-1.5 text-xs">
+ Affected Monitors
+ </p>
+ <AffectedMonitors monitors={monitors} />
+ </div>
+ ) : null}
<div>
<p className="text-muted-foreground mb-1.5 text-xs">
Last Updates
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index d36d587f1..20b179adc 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -1,16 +1,25 @@
import type { Metadata } from "next";
+import Link from "next/link";
import { notFound } from "next/navigation";
+import { Button } from "@openstatus/ui";
+
import {
defaultMetadata,
ogMetadata,
twitterMetadata,
} from "@/app/shared-metadata";
+import { EmptyState } from "@/components/dashboard/empty-state";
import { Header } from "@/components/dashboard/header";
import { IncidentList } from "@/components/status-page/incident-list";
import { MonitorList } from "@/components/status-page/monitor-list";
import { api } from "@/trpc/server";
+const url =
+ process.env.NODE_ENV === "development"
+ ? "http://localhost:3000"
+ : "https://www.openstatus.dev";
+
type Props = {
params: { domain: string };
searchParams: { [key: string]: string | string[] | undefined };
@@ -24,6 +33,11 @@ export default async function Page({ params }: Props) {
if (!page) {
return notFound();
}
+
+ const isEmptyState = !(
+ Boolean(page.monitors.length) || Boolean(page.incidents.length)
+ );
+
return (
<div className="grid gap-6">
<Header
@@ -31,14 +45,27 @@ export default async function Page({ params }: Props) {
description={page.description}
className="text-left"
/>
- <MonitorList monitors={page.monitors} />
- {page.monitors?.length > 0 ? (
- <IncidentList
- incidents={page.incidents}
- monitors={page.monitors}
- context="latest"
+ {isEmptyState ? (
+ <EmptyState
+ icon="activity"
+ title="Missing Monitors"
+ description="Fill your status page with monitors."
+ action={
+ <Button asChild>
+ <Link href={`${url}/app`}>Go to Dashboard</Link>
+ </Button>
+ }
/>
- ) : null}
+ ) : (
+ <>
+ <MonitorList monitors={page.monitors} />
+ <IncidentList
+ incidents={page.incidents}
+ monitors={page.monitors}
+ context="latest"
+ />
+ </>
+ )}
</div>
);
}
diff --git a/apps/web/src/components/forms/incident-form.tsx b/apps/web/src/components/forms/incident-form.tsx
index 38cc32850..b590fddb3 100644
--- a/apps/web/src/components/forms/incident-form.tsx
+++ b/apps/web/src/components/forms/incident-form.tsx
@@ -6,7 +6,10 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import * as z from "zod";
-import type { allMonitorsExtendedSchema } from "@openstatus/db/src/schema";
+import type {
+ allMonitorsExtendedSchema,
+ Page,
+} from "@openstatus/db/src/schema";
import {
availableStatus,
insertIncidentSchema,
@@ -57,12 +60,14 @@ type MonitorsProps = z.infer<typeof allMonitorsExtendedSchema>;
interface Props {
defaultValues?: IncidentProps;
monitors?: MonitorsProps;
+ pages?: Page[]; //
workspaceSlug: string;
}
export function IncidentForm({
defaultValues,
monitors,
+ pages,
workspaceSlug,
}: Props) {
const form = useForm<IncidentProps>({
@@ -72,6 +77,7 @@ export function IncidentForm({
title: defaultValues?.title || "",
status: defaultValues?.status || "investigating",
monitors: defaultValues?.monitors || [],
+ pages: defaultValues?.pages || [],
workspaceSlug,
// include update on creation
message: "",
@@ -190,9 +196,11 @@ export function IncidentForm({
<FormItem className="sm:col-span-full">
<div className="mb-4">
<FormLabel>Monitors</FormLabel>
+ {/* TODO: second phrase can be set inside of a (?) tooltip */}
<FormDescription>
Select the monitors that you want to refer the incident
- to.
+ to. It will be displayed on the status page they are
+ attached to.
</FormDescription>
</div>
<div className="grid grid-cols-2 gap-4 sm:grid-cols-4">
@@ -252,6 +260,66 @@ export function IncidentForm({
</FormItem>
)}
/>
+ <FormField
+ control={form.control}
+ name="pages"
+ render={() => (
+ <FormItem className="sm:col-span-full">
+ <div className="mb-4">
+ <FormLabel>Pages</FormLabel>
+ <FormDescription>
+ Select the pages that you want to refer the incident to.
+ </FormDescription>
+ </div>
+ <div className="grid grid-cols-2 gap-4 sm:grid-cols-4">
+ {pages?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="pages"
+ render={({ field }) => {
+ return (
+ <FormItem
+ key={item.id}
+ className="flex flex-row items-start space-x-3 space-y-0"
+ >
+ <FormControl>
+ <Checkbox
+ checked={field.value?.includes(item.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([
+ ...(field.value || []),
+ item.id,
+ ])
+ : field.onChange(
+ field.value?.filter(
+ (value) => value !== item.id,
+ ),
+ );
+ }}
+ />
+ </FormControl>
+ <div className="grid gap-1.5 leading-none">
+ <div className="flex items-center gap-2">
+ <FormLabel className="font-normal">
+ {item.title}
+ </FormLabel>
+ </div>
+ <p className="text-muted-foreground truncate text-sm">
+ {item.description}
+ </p>
+ </div>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ </div>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
</div>
</div>
{/* include update on creation */}
diff --git a/apps/web/src/components/status-page/incident-list.tsx b/apps/web/src/components/status-page/incident-list.tsx
index 02fccdb8f..0dd0db424 100644
--- a/apps/web/src/components/status-page/incident-list.tsx
+++ b/apps/web/src/components/status-page/incident-list.tsx
@@ -45,27 +45,35 @@ export const IncidentList = ({
{context === "all" ? "All incidents" : "Latest incidents"}
</h2>
{_incidents.map((incident) => {
+ const affectedMonitors = incident.monitorsToIncidents
+ .map(({ monitorId }) => {
+ const monitor = monitors.find(({ id }) => monitorId === id);
+ return monitor || undefined;
+ })
+ .filter(notEmpty);
return (
<div key={incident.id} className="grid gap-4 text-left">
<div className="max-w-3xl font-semibold">
{incident.title}
<StatusBadge status={incident.status} className="ml-2" />
</div>
- <div className="overflow-hidden text-ellipsis">
- <p className="text-muted-foreground mb-2 text-xs">
- Affected Monitors
- </p>
- <AffectedMonitors
- monitors={incident.monitorsToIncidents
- .map(({ monitorId }) => {
- const monitor = monitors.find(
- ({ id }) => monitorId === id,
- );
- return monitor || undefined;
- })
- .filter(notEmpty)}
- />
- </div>
+ {Boolean(affectedMonitors.length) ? (
+ <div className="overflow-hidden text-ellipsis">
+ <p className="text-muted-foreground mb-2 text-xs">
+ Affected Monitors
+ </p>
+ <AffectedMonitors
+ monitors={incident.monitorsToIncidents
+ .map(({ monitorId }) => {
+ const monitor = monitors.find(
+ ({ id }) => monitorId === id,
+ );
+ return monitor || undefined;
+ })
+ .filter(notEmpty)}
+ />
+ </div>
+ ) : null}
<div>
<p className="text-muted-foreground mb-2 text-xs">
Latest Updates
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
index 14f5618cc..40751abfb 100644
--- a/apps/web/src/components/status-page/monitor-list.tsx
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -1,10 +1,7 @@
-import Link from "next/link";
import type { z } from "zod";
import type { selectPublicMonitorSchema } from "@openstatus/db/src/schema";
-import { Button } from "@openstatus/ui";
-import { EmptyState } from "../dashboard/empty-state";
import { Monitor } from "./monitor";
export const MonitorList = ({
@@ -12,31 +9,14 @@ export const MonitorList = ({
}: {
monitors: z.infer<typeof selectPublicMonitorSchema>[];
}) => {
- const url =
- process.env.NODE_ENV === "development"
- ? "http://localhost:3000"
- : "https://www.openstatus.dev";
return (
<div className="grid gap-4">
- {Boolean(monitors.length) ? (
- monitors.map((monitor, index) => (
- <div key={index}>
- {/* Fetch tracker and data */}
- <Monitor monitor={monitor} />
- </div>
- ))
- ) : (
- <EmptyState
- icon="activity"
- title="Missing Monitors"
- description="Fill your status page with monitors."
- action={
- <Button asChild>
- <Link href={`${url}/app`}>Go to Dashboard</Link>
- </Button>
- }
- />
- )}
+ {monitors.map((monitor, index) => (
+ <div key={index}>
+ {/* Fetch tracker and data */}
+ <Monitor monitor={monitor} />
+ </div>
+ ))}
</div>
);
};
diff --git a/packages/api/src/router/incident.ts b/packages/api/src/router/incident.ts
index 2aa7bbe3f..9d4da4e3d 100644
--- a/packages/api/src/router/incident.ts
+++ b/packages/api/src/router/incident.ts
@@ -8,6 +8,7 @@ import {
insertIncidentSchemaWithMonitors,
insertIncidentUpdateSchema,
monitorsToIncidents,
+ pagesToIncidents,
selectIncidentSchema,
selectIncidentUpdateSchema,
selectMonitorSchema,
@@ -30,7 +31,7 @@ export const incidentRouter = createTRPCRouter({
});
if (!result) return;
- const { id, workspaceSlug, monitors, date, ...incidentInput } =
+ const { id, workspaceSlug, monitors, pages, date, ...incidentInput } =
opts.input;
const newIncident = await opts.ctx.db
@@ -54,16 +55,31 @@ export const incidentRouter = createTRPCRouter({
// await opts.ctx.db.insert(monitorsToIncidents).values(values).run();
// }
- await opts.ctx.db
- .insert(monitorsToIncidents)
- .values(
- monitors.map((monitor) => ({
- monitorId: monitor,
- incidentId: newIncident.id,
- })),
- )
- .returning()
- .get();
+ if (monitors.length > 0) {
+ await opts.ctx.db
+ .insert(monitorsToIncidents)
+ .values(
+ monitors.map((monitor) => ({
+ monitorId: monitor,
+ incidentId: newIncident.id,
+ })),
+ )
+ .returning()
+ .get();
+ }
+
+ if (pages.length > 0) {
+ await opts.ctx.db
+ .insert(pagesToIncidents)
+ .values(
+ pages.map((page) => ({
+ pageId: page,
+ incidentId: newIncident.id,
+ })),
+ )
+ .returning()
+ .get();
+ }
return newIncident;
}),
@@ -103,7 +119,7 @@ export const incidentRouter = createTRPCRouter({
});
if (!data) return;
- const { monitors, workspaceSlug, ...incidentInput } = opts.input;
+ const { monitors, pages, workspaceSlug, ...incidentInput } = opts.input;
if (!incidentInput.id) return;
@@ -155,6 +171,45 @@ export const incidentRouter = createTRPCRouter({
.run();
}
+ const currentPagesToIncidents = await opts.ctx.db
+ .select()
+ .from(pagesToIncidents)
+ .where(eq(pagesToIncidents.incidentId, currentIncident.id))
+ .all();
+
+ const currentPagesToIncidentsIds = currentPagesToIncidents.map(
+ ({ pageId }) => pageId,
+ );
+
+ const removedPages = currentPagesToIncidentsIds.filter(
+ (x) => !pages?.includes(x),
+ );
+
+ const addedPages = pages?.filter(
+ (x) => !currentPagesToIncidentsIds?.includes(x),
+ );
+
+ if (addedPages && addedPages.length > 0) {
+ const values = addedPages.map((pageId) => ({
+ pageId,
+ incidentId: currentIncident.id,
+ }));
+
+ await opts.ctx.db.insert(pagesToIncidents).values(values).run();
+ }
+
+ if (removedPages && removedPages.length > 0) {
+ await opts.ctx.db
+ .delete(pagesToIncidents)
+ .where(
+ and(
+ eq(pagesToIncidents.incidentId, currentIncident.id),
+ inArray(pagesToIncidents.pageId, removedPages),
+ ),
+ )
+ .run();
+ }
+
return currentIncident;
}),
@@ -272,6 +327,9 @@ export const incidentRouter = createTRPCRouter({
monitorsToIncidents: z
.array(z.object({ incidentId: z.number(), monitorId: z.number() }))
.default([]),
+ pagesToIncidents: z
+ .array(z.object({ incidentId: z.number(), pageId: z.number() }))
+ .default([]),
incidentUpdates: z.array(selectIncidentUpdateSchema),
date: z.date().default(new Date()),
});
@@ -280,6 +338,7 @@ export const incidentRouter = createTRPCRouter({
where: eq(incident.id, opts.input.id),
with: {
monitorsToIncidents: true,
+ pagesToIncidents: true,
incidentUpdates: {
orderBy: (incidentUpdate, { desc }) => [
desc(incidentUpdate.createdAt),
diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.ts
index 111e9b233..2908a5b65 100644
--- a/packages/api/src/router/page.ts
+++ b/packages/api/src/router/page.ts
@@ -2,7 +2,7 @@ import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { analytics, trackAnalytics } from "@openstatus/analytics";
-import { and, eq, inArray, not, sql } from "@openstatus/db";
+import { and, eq, inArray, not, or, sql } from "@openstatus/db";
import {
incident,
insertPageSchemaWithMonitors,
@@ -10,6 +10,7 @@ import {
monitorsToIncidents,
monitorsToPages,
page,
+ pagesToIncidents,
selectPublicPageSchemaWithRelation,
user,
usersToWorkspaces,
@@ -287,15 +288,33 @@ export const pageRouter = createTRPCRouter({
.all()
: [];
- const incidentsId = monitorsToIncidentsResult.map(
+ const incidentsToPagesResult = await opts.ctx.db
+ .select()
+ .from(pagesToIncidents)
+ .where(eq(pagesToIncidents.pageId, result.id))
+ .all();
+
+ const monitorIncidentIds = monitorsToIncidentsResult.map(
+ ({ incidentId }) => incidentId,
+ );
+
+ const pageIncidentIds = incidentsToPagesResult.map(
({ incidentId }) => incidentId,
);
+ const incidentIds = Array.from(
+ new Set([...monitorIncidentIds, ...pageIncidentIds]),
+ );
+
const incidents =
- incidentsId.length > 0
+ incidentIds.length > 0
? await opts.ctx.db.query.incident.findMany({
- where: and(inArray(incident.id, incidentsId)),
- with: { incidentUpdates: true, monitorsToIncidents: true },
+ where: or(inArray(incident.id, incidentIds)),
+ with: {
+ incidentUpdates: true,
+ monitorsToIncidents: true,
+ pagesToIncidents: true,
+ },
})
: [];
diff --git a/packages/db/drizzle/0009_small_maximus.sql b/packages/db/drizzle/0009_small_maximus.sql
new file mode 100644
index 000000000..d2093dae7
--- /dev/null
+++ b/packages/db/drizzle/0009_small_maximus.sql
@@ -0,0 +1,7 @@
+CREATE TABLE `incidents_to_pages` (
+ `page_id` integer NOT NULL,
+ `incident_id` integer NOT NULL,
+ PRIMARY KEY(`incident_id`, `page_id`),
+ FOREIGN KEY (`page_id`) REFERENCES `page`(`id`) ON UPDATE no action ON DELETE cascade,
+ FOREIGN KEY (`incident_id`) REFERENCES `incident`(`id`) ON UPDATE no action ON DELETE cascade
+);
diff --git a/packages/db/drizzle/meta/0009_snapshot.json b/packages/db/drizzle/meta/0009_snapshot.json
new file mode 100644
index 000000000..78d9ad4e0
--- /dev/null
+++ b/packages/db/drizzle/meta/0009_snapshot.json
@@ -0,0 +1,1016 @@
+{
+ "version": "5",
+ "dialect": "sqlite",
+ "id": "0f3dddb6-09cf-46a4-b12c-c5bb82475b94",
+ "prevId": "72f58965-4d96-43e5-9101-3ceb67dac648",
+ "tables": {
+ "incident": {
+ "name": "incident",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text(4)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "incident_workspace_id_workspace_id_fk": {
+ "name": "incident_workspace_id_workspace_id_fk",
+ "tableFrom": "incident",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "incident_update": {
+ "name": "incident_update",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text(4)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "date": {
+ "name": "date",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "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": {}
+ },
+ "incidents_to_monitors": {
+ "name": "incidents_to_monitors",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "incidents_to_monitors_monitor_id_monitor_id_fk": {
+ "name": "incidents_to_monitors_monitor_id_monitor_id_fk",
+ "tableFrom": "incidents_to_monitors",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "incidents_to_monitors_incident_id_incident_id_fk": {
+ "name": "incidents_to_monitors_incident_id_incident_id_fk",
+ "tableFrom": "incidents_to_monitors",
+ "tableTo": "incident",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "incidents_to_monitors_monitor_id_incident_id_pk": {
+ "columns": [
+ "incident_id",
+ "monitor_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "incidents_to_pages": {
+ "name": "incidents_to_pages",
+ "columns": {
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "incidents_to_pages_page_id_page_id_fk": {
+ "name": "incidents_to_pages_page_id_page_id_fk",
+ "tableFrom": "incidents_to_pages",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "incidents_to_pages_incident_id_incident_id_fk": {
+ "name": "incidents_to_pages_incident_id_incident_id_fk",
+ "tableFrom": "incidents_to_pages",
+ "tableTo": "incident",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "incidents_to_pages_page_id_incident_id_pk": {
+ "columns": [
+ "incident_id",
+ "page_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "integration": {
+ "name": "integration",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "credential": {
+ "name": "credential",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "data": {
+ "name": "data",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "integration_workspace_id_workspace_id_fk": {
+ "name": "integration_workspace_id_workspace_id_fk",
+ "tableFrom": "integration",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "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,
+ "default": "''"
+ },
+ "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
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "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": "'active'"
+ },
+ "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(2048)",
+ "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": "''"
+ },
+ "headers": {
+ "name": "headers",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "body": {
+ "name": "body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "method": {
+ "name": "method",
+ "type": "text(2)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'GET'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "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
+ },
+ "first_name": {
+ "name": "first_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "last_name": {
+ "name": "last_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "photo_url": {
+ "name": "photo_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "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
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripe_id": {
+ "name": "stripe_id",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "subscription_id": {
+ "name": "subscription_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "plan": {
+ "name": "plan",
+ "type": "text(2)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "ends_at": {
+ "name": "ends_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "paid_until": {
+ "name": "paid_until",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "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": {}
+ },
+ "notification": {
+ "name": "notification",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "data": {
+ "name": "data",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "notification_workspace_id_workspace_id_fk": {
+ "name": "notification_workspace_id_workspace_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "notifications_to_monitors": {
+ "name": "notifications_to_monitors",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "notification_id": {
+ "name": "notification_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "notifications_to_monitors_monitor_id_monitor_id_fk": {
+ "name": "notifications_to_monitors_monitor_id_monitor_id_fk",
+ "tableFrom": "notifications_to_monitors",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notifications_to_monitors_notification_id_notification_id_fk": {
+ "name": "notifications_to_monitors_notification_id_notification_id_fk",
+ "tableFrom": "notifications_to_monitors",
+ "tableTo": "notification",
+ "columnsFrom": [
+ "notification_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "notifications_to_monitors_monitor_id_notification_id_pk": {
+ "columns": [
+ "monitor_id",
+ "notification_id"
+ ]
+ }
+ },
+ "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 249dd03d3..771d2a724 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -64,6 +64,13 @@
"when": 1695756345957,
"tag": "0008_overjoyed_sunset_bain",
"breakpoints": true
+ },
+ {
+ "idx": 9,
+ "version": "5",
+ "when": 1697285841283,
+ "tag": "0009_small_maximus",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/packages/db/src/schema/incident.ts b/packages/db/src/schema/incident.ts
index baf0dbb51..1f6edc664 100644
--- a/packages/db/src/schema/incident.ts
+++ b/packages/db/src/schema/incident.ts
@@ -9,6 +9,7 @@ import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import * as z from "zod";
import { monitor } from "./monitor";
+import { page } from "./page";
import { workspace } from "./workspace";
export const availableStatus = [
@@ -57,6 +58,7 @@ export const incidentUpdate = sqliteTable("incident_update", {
export const incidentRelations = relations(incident, ({ one, many }) => ({
monitorsToIncidents: many(monitorsToIncidents),
+ pagesToIncidents: many(pagesToIncidents),
incidentUpdates: many(incidentUpdate),
workspace: one(workspace, {
fields: [incident.workspaceId],
@@ -100,6 +102,35 @@ export const monitorsToIncidentsRelations = relations(
}),
);
+export const pagesToIncidents = sqliteTable(
+ "incidents_to_pages",
+ {
+ pageId: integer("page_id")
+ .notNull()
+ .references(() => page.id, { onDelete: "cascade" }),
+ incidentId: integer("incident_id")
+ .notNull()
+ .references(() => incident.id, { onDelete: "cascade" }),
+ },
+ (t) => ({
+ pk: primaryKey(t.pageId, t.incidentId),
+ }),
+);
+
+export const pagesToIncidentsRelations = relations(
+ pagesToIncidents,
+ ({ one }) => ({
+ page: one(page, {
+ fields: [pagesToIncidents.pageId],
+ references: [page.id],
+ }),
+ incident: one(incident, {
+ fields: [pagesToIncidents.incidentId],
+ references: [incident.id],
+ }),
+ }),
+);
+
// Schema for inserting a Incident - can be used to validate API requests
export const insertIncidentSchema = createInsertSchema(incident).extend({
title: z.string().default(""),
@@ -108,7 +139,8 @@ export const insertIncidentSchema = createInsertSchema(incident).extend({
date: z.date().optional().default(new Date()),
// date: z.number().optional().default(new Date().getTime()),
workspaceSlug: z.string(),
- monitors: z.number().array().min(1),
+ monitors: z.number().array(),
+ pages: z.number().array(),
});
export const insertIncidentUpdateSchema = createInsertSchema(
@@ -125,9 +157,9 @@ export const insertIncidentSchemaWithIncidentUpdates =
incidentUpdates: insertIncidentUpdateSchema.array(),
});
-// TODO: remove!
+// TODO: remove!!!
export const insertIncidentSchemaWithMonitors = insertIncidentSchema.extend({
- monitors: z.number().array().min(1),
+ monitors: z.number().array(),
});
export const selectIncidentSchema = createSelectSchema(incident).extend({
diff --git a/packages/db/src/schema/page.ts b/packages/db/src/schema/page.ts
index 0b7e5bce9..c34247a05 100644
--- a/packages/db/src/schema/page.ts
+++ b/packages/db/src/schema/page.ts
@@ -3,6 +3,7 @@ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
+import { pagesToIncidents } from "./incident";
import { monitorsToPages } from "./monitor";
import { workspace } from "./workspace";
@@ -30,6 +31,7 @@ export const page = sqliteTable("page", {
export const pageRelations = relations(page, ({ many, one }) => ({
monitorsToPages: many(monitorsToPages),
+ pagesToIncidents: many(pagesToIncidents),
workspace: one(workspace, {
fields: [page.workspaceId],
references: [workspace.id],