Skip to content

Open-source status page, incident response and uptime monitoring

feat: maintenances (#868)

Maximilian Kaskea3c6beec1da8
diff --git a/apps/docs/packages/status-widget.mdx b/apps/docs/packages/status-widget.mdx
index 759cdfc0b..a8cdaf8b7 100644
--- a/apps/docs/packages/status-widget.mdx
+++ b/apps/docs/packages/status-widget.mdx
@@ -120,7 +120,7 @@ const dictionary = {
},
under_maintenance: {
label: "Under Maintenance",
- color: "bg-gray-500",
+ color: "bg-blue-500",
},
} as const;
diff --git a/apps/server/src/public/status.ts b/apps/server/src/public/status.ts
index 0a639db21..42a1a4389 100644
--- a/apps/server/src/public/status.ts
+++ b/apps/server/src/public/status.ts
@@ -1,9 +1,10 @@
import { Hono } from "hono";
import { endTime, setMetric, startTime } from "hono/timing";
-import { and, db, eq, inArray, isNull } from "@openstatus/db";
+import { and, db, eq, gte, inArray, isNull, lte } from "@openstatus/db";
import {
incidentTable,
+ maintenance,
monitor,
monitorsToPages,
monitorsToStatusReport,
@@ -44,10 +45,16 @@ status.get("/:slug", async (c) => {
return c.json({ status: Status.Unknown });
}
- const { pageStatusReportData, monitorStatusReportData, ongoingIncidents } =
- await getStatusPageData(currentPage.id);
+ const {
+ pageStatusReportData,
+ monitorStatusReportData,
+ ongoingIncidents,
+ maintenanceData,
+ } = await getStatusPageData(currentPage.id);
endTime(c, "database");
+ console.log(maintenanceData);
+
const statusReports = [
...pageStatusReportData,
...monitorStatusReportData,
@@ -55,7 +62,11 @@ status.get("/:slug", async (c) => {
return item.status_report;
});
- const tracker = new Tracker({ incidents: ongoingIncidents, statusReports });
+ const tracker = new Tracker({
+ incidents: ongoingIncidents,
+ statusReports,
+ maintenances: maintenanceData,
+ });
const status = tracker.currentStatus;
await redis.set(slug, status, { ex: 60 }); // 1m cache
@@ -73,8 +84,8 @@ async function getStatusPageData(pageId: number) {
and(
eq(monitorsToPages.monitorId, monitor.id),
eq(monitor.active, true),
- eq(monitorsToPages.pageId, pageId),
- ),
+ eq(monitorsToPages.pageId, pageId)
+ )
)
.all();
@@ -94,7 +105,7 @@ async function getStatusPageData(pageId: number) {
.from(monitorsToStatusReport)
.innerJoin(
statusReport,
- eq(monitorsToStatusReport.statusReportId, statusReport.id),
+ eq(monitorsToStatusReport.statusReportId, statusReport.id)
)
.where(inArray(monitorsToStatusReport.monitorId, monitorIds))
.all();
@@ -106,8 +117,8 @@ async function getStatusPageData(pageId: number) {
statusReport,
and(
eq(pagesToStatusReports.statusReportId, statusReport.id),
- eq(pagesToStatusReports.pageId, pageId),
- ),
+ eq(pagesToStatusReports.pageId, pageId)
+ )
)
.all();
@@ -117,22 +128,39 @@ async function getStatusPageData(pageId: number) {
.where(
and(
isNull(incidentTable.resolvedAt),
- inArray(incidentTable.monitorId, monitorIds),
- ),
+ inArray(incidentTable.monitorId, monitorIds)
+ )
)
.all();
- const [monitorStatusReportData, pageStatusReportData, ongoingIncidents] =
- await Promise.all([
- monitorStatusReportQuery,
- pageStatusReportDataQuery,
- ongoingIncidentsQuery,
- ]);
+ const ongoingMaintenancesQuery = db
+ .select()
+ .from(maintenance)
+ .where(
+ and(
+ eq(maintenance.pageId, pageId),
+ lte(maintenance.from, new Date()),
+ gte(maintenance.to, new Date())
+ )
+ );
+
+ const [
+ monitorStatusReportData,
+ pageStatusReportData,
+ ongoingIncidents,
+ maintenanceData,
+ ] = await Promise.all([
+ monitorStatusReportQuery,
+ pageStatusReportDataQuery,
+ ongoingIncidentsQuery,
+ ongoingMaintenancesQuery,
+ ]);
return {
// monitorData,
pageStatusReportData,
monitorStatusReportData,
+ maintenanceData,
ongoingIncidents,
};
}
diff --git a/apps/web/public/assets/changelog/maintenance-status.png b/apps/web/public/assets/changelog/maintenance-status.png
new file mode 100644
index 000000000..5204d1dc6
Binary files /dev/null and b/apps/web/public/assets/changelog/maintenance-status.png differ
diff --git a/apps/web/src/app/api/checker/cron/_cron.ts b/apps/web/src/app/api/checker/cron/_cron.ts
index 782ddad17..f27997bfd 100644
--- a/apps/web/src/app/api/checker/cron/_cron.ts
+++ b/apps/web/src/app/api/checker/cron/_cron.ts
@@ -3,9 +3,11 @@ import type { google } from "@google-cloud/tasks/build/protos/protos";
import type { NextRequest } from "next/server";
import { z } from "zod";
-import { and, db, eq } from "@openstatus/db";
+import { and, db, eq, gte, lte, notInArray } from "@openstatus/db";
import type { MonitorStatus } from "@openstatus/db/src/schema";
import {
+ maintenance,
+ maintenancesToMonitors,
monitor,
monitorStatusTable,
selectMonitorSchema,
@@ -43,16 +45,39 @@ export const cron = async ({
const parent = client.queuePath(
env.GCP_PROJECT_ID,
env.GCP_LOCATION,
- periodicity,
+ periodicity
);
const timestamp = Date.now();
+ const currentMaintenance = db
+ .select({ id: maintenance.id })
+ .from(maintenance)
+ .where(
+ and(lte(maintenance.from, new Date()), gte(maintenance.to, new Date()))
+ )
+ .as("currentMaintenance");
+
+ const currentMaintenanceMonitors = db
+ .select({ id: maintenancesToMonitors.monitorId })
+ .from(maintenancesToMonitors)
+ .innerJoin(
+ currentMaintenance,
+ eq(maintenancesToMonitors.maintenanceId, currentMaintenance.id)
+ );
+
const result = await db
.select()
.from(monitor)
- .where(and(eq(monitor.periodicity, periodicity), eq(monitor.active, true)))
+ .where(
+ and(
+ eq(monitor.periodicity, "10m"),
+ eq(monitor.active, true),
+ notInArray(monitor.id, currentMaintenanceMonitors)
+ )
+ )
.all();
+
console.log(`Start cron for ${periodicity}`);
const monitors = z.array(selectMonitorSchema).parse(result);
@@ -102,7 +127,7 @@ export const cron = async ({
const failed = allRequests.filter((r) => r.status === "rejected").length;
console.log(
- `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`,
+ `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`
);
};
// timestamp needs to be in ms
diff --git a/apps/web/src/app/api/og/_components/status-check.tsx b/apps/web/src/app/api/og/_components/status-check.tsx
index a8ee8455c..daebb51ba 100644
--- a/apps/web/src/app/api/og/_components/status-check.tsx
+++ b/apps/web/src/app/api/og/_components/status-check.tsx
@@ -9,6 +9,8 @@ export function StatusCheck({ tracker }: { tracker: Tracker }) {
// FIXME: move icons into @openstatus/tracker lib
function getVariant() {
switch (details.variant) {
+ case "maintenance":
+ return Hammer;
case "down":
return Minus;
case "degraded":
@@ -34,6 +36,26 @@ export function StatusCheck({ tracker }: { tracker: Tracker }) {
);
}
+function Hammer() {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="40"
+ height="40"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ >
+ <path d="m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9" />
+ <path d="m18 15 4-4" />
+ <path d="m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5" />
+ </svg>
+ );
+}
+
function Check() {
return (
<svg
diff --git a/apps/web/src/app/api/og/page/route.tsx b/apps/web/src/app/api/og/page/route.tsx
index a2b4f478a..94d1c790f 100644
--- a/apps/web/src/app/api/og/page/route.tsx
+++ b/apps/web/src/app/api/og/page/route.tsx
@@ -12,7 +12,7 @@ export const runtime = "edge";
export async function GET(req: Request) {
const [interRegularData, interLightData, calSemiBoldData] = await Promise.all(
- [interRegular, interLight, calSemiBold],
+ [interRegular, interLight, calSemiBold]
);
const { searchParams } = new URL(req.url);
@@ -30,12 +30,15 @@ export async function GET(req: Request) {
const tracker = new Tracker({
incidents: passwordProtected ? undefined : page?.incidents,
statusReports: passwordProtected ? undefined : page?.statusReports,
+ maintenances: passwordProtected ? undefined : page?.maintenances,
});
return new ImageResponse(
- <BasicLayout title={title} description={description} tw="py-24 px-24">
- <StatusCheck tracker={tracker} />
- </BasicLayout>,
+ (
+ <BasicLayout title={title} description={description} tw="py-24 px-24">
+ <StatusCheck tracker={tracker} />
+ </BasicLayout>
+ ),
{
...SIZE,
fonts: [
@@ -58,6 +61,6 @@ export async function GET(req: Request) {
weight: 600,
},
],
- },
+ }
);
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/overview/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/overview/page.tsx
index a09b08a4d..599cf2bf4 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/overview/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/overview/page.tsx
@@ -2,10 +2,6 @@ import * as React from "react";
import { PathCard } from "./_components/path-card";
import { api } from "@/trpc/server";
-import { Suspense } from "react";
-import { Skeleton } from "@openstatus/ui/src/components/skeleton";
-import Loading from "../loading";
-import { auth } from "@/lib/auth";
import { SessionTable } from "./_components/session-table";
import { z } from "zod";
@@ -18,22 +14,18 @@ export default async function RUMPage({
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) {
- const session = await auth();
- if (!session?.user) {
- return <Loading />;
- }
+ const search = searchParamsSchema.safeParse(searchParams);
- const data = searchParamsSchema.parse(searchParams);
const applications = await api.workspace.getApplicationWorkspaces.query();
- if (applications.length === 0 || !applications[0].dsn) {
- return null;
- }
+ const dsn = applications?.[0]?.dsn;
+
+ if (!search.success || !dsn) return null;
return (
<>
- <PathCard dsn={applications[0].dsn} path={data.path} />
+ <PathCard dsn={dsn} path={search.data.path} />
<div>
- <SessionTable dsn={applications[0].dsn} path={data.path} />
+ <SessionTable dsn={dsn} path={search.data.path} />
</div>
</>
);
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/page.tsx
index 879a55255..28d796898 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/page.tsx
@@ -14,8 +14,8 @@ const redis = Redis.fromEnv();
export default async function RUMPage() {
const applications = await api.workspace.getApplicationWorkspaces.query();
-
const session = await auth();
+
if (!session?.user) return null;
const accessRequested = await redis.sismember(
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx
index 6959af554..f0e985646 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/(overview)/layout.tsx
@@ -12,7 +12,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
return (
<AppPageLayout withHelpCallout>
<Header
- title="Pages"
+ title="Status Pages"
description="Overview of all your pages."
actions={
<ButtonWithDisableTooltip
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/(overview)/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/(overview)/page.tsx
new file mode 100644
index 000000000..277e961ed
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/(overview)/page.tsx
@@ -0,0 +1,41 @@
+import { EmptyState } from "@/components/dashboard/empty-state";
+import { columns } from "@/components/data-table/maintenance/columns";
+import { DataTable } from "@/components/data-table/maintenance/data-table";
+import { api } from "@/trpc/server";
+import { Button } from "@openstatus/ui";
+import Link from "next/link";
+
+export default async function MaintenancePage({
+ params,
+}: {
+ params: { workspaceSlug: string; id: string };
+}) {
+ const maintenances = await api.maintenance.getByPage.query({
+ id: Number(params.id),
+ });
+
+ if (maintenances?.length === 0)
+ return (
+ <EmptyState
+ icon="hammer"
+ title="No maintenances"
+ description="Add a maintenance to your status page."
+ action={
+ <Button asChild>
+ <Link href="./maintenances/new">Create a maintenance</Link>
+ </Button>
+ }
+ />
+ );
+
+ return (
+ <div className="flex flex-col gap-4">
+ <div>
+ <Button size="sm" asChild>
+ <Link href="./maintenances/new">Create a maintenance</Link>
+ </Button>
+ </div>
+ <DataTable data={maintenances} columns={columns} />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/[maintenanceId]/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/[maintenanceId]/edit/page.tsx
new file mode 100644
index 000000000..8ce6db982
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/[maintenanceId]/edit/page.tsx
@@ -0,0 +1,24 @@
+import { MaintenanceForm } from "@/components/forms/maintenance/form";
+import { api } from "@/trpc/server";
+
+export default async function MaintenancePage({
+ params,
+}: {
+ params: { workspaceSlug: string; id: string; maintenanceId: string };
+}) {
+ const monitors = await api.monitor.getMonitorsByPageId.query({
+ id: Number(params.id),
+ });
+ const maintenance = await api.maintenance.getById.query({
+ id: Number(params.maintenanceId),
+ });
+
+ return (
+ <MaintenanceForm
+ defaultValues={maintenance}
+ pageId={Number(params.id)}
+ defaultSection="connect"
+ monitors={monitors}
+ />
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/new/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/new/page.tsx
new file mode 100644
index 000000000..4d81588c2
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/maintenances/new/page.tsx
@@ -0,0 +1,21 @@
+import { MaintenanceForm } from "@/components/forms/maintenance/form";
+import { api } from "@/trpc/server";
+
+export default async function MaintenancePage({
+ params,
+}: {
+ params: { workspaceSlug: string; id: string };
+}) {
+ const monitors = await api.monitor.getMonitorsByPageId.query({
+ id: Number(params.id),
+ });
+
+ return (
+ <MaintenanceForm
+ nextUrl="./" // back to the overview page
+ defaultSection="connect"
+ pageId={Number(params.id)}
+ monitors={monitors}
+ />
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/_components/header.tsx b/apps/web/src/app/status-page/[domain]/_components/header.tsx
index 9d9f25831..5f533e403 100644
--- a/apps/web/src/app/status-page/[domain]/_components/header.tsx
+++ b/apps/web/src/app/status-page/[domain]/_components/header.tsx
@@ -46,6 +46,7 @@ export function Header({ navigation, plan, page }: Props) {
<TabsContainer className="-mb-[14px] hidden sm:block">
{navigation.map(({ label, href, disabled, segment }) => {
const active = segment === selectedSegment;
+ if (disabled) return null;
return (
<TabsLink key={segment} {...{ active, href, label, disabled }}>
{label}
diff --git a/apps/web/src/app/status-page/[domain]/_components/menu.tsx b/apps/web/src/app/status-page/[domain]/_components/menu.tsx
index 9f947452b..0c475123b 100644
--- a/apps/web/src/app/status-page/[domain]/_components/menu.tsx
+++ b/apps/web/src/app/status-page/[domain]/_components/menu.tsx
@@ -53,6 +53,7 @@ export function Menu({ navigation }: Props) {
<ul className="grid gap-1">
{navigation.map(({ href, label, segment, disabled }) => {
const active = segment === selectedSegment;
+ if (disabled) return null;
return (
<li key={href} className="w-full">
<AppLink {...{ href, label, active, disabled }} />
diff --git a/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx b/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx
index a1dbae017..8737d16e9 100644
--- a/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/incidents/[id]/page.tsx
@@ -21,7 +21,7 @@ export default async function IncidentPage({
if (!report) return notFound();
const affectedMonitors = report.monitorsToStatusReports.map(
- ({ monitor }) => monitor,
+ ({ monitor }) => monitor
);
return (
@@ -32,6 +32,7 @@ export default async function IncidentPage({
<StatusReportDescription
report={report}
monitors={affectedMonitors}
+ className="mt-2"
/>
}
actions={<CopyLinkButton />}
diff --git a/apps/web/src/app/status-page/[domain]/layout.tsx b/apps/web/src/app/status-page/[domain]/layout.tsx
index bd89e6396..eb62e8339 100644
--- a/apps/web/src/app/status-page/[domain]/layout.tsx
+++ b/apps/web/src/app/status-page/[domain]/layout.tsx
@@ -32,6 +32,12 @@ export default async function StatusPageLayout({ children, params }: Props) {
segment: null,
href: setPrefixUrl("/", params),
},
+ {
+ label: "Maintenances",
+ segment: "maintenances",
+ href: setPrefixUrl("/maintenances", params),
+ disabled: page.maintenances.length === 0,
+ },
{
label: "Incidents",
segment: "incidents",
diff --git a/apps/web/src/app/status-page/[domain]/maintenances/page.tsx b/apps/web/src/app/status-page/[domain]/maintenances/page.tsx
new file mode 100644
index 000000000..4751742e6
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/maintenances/page.tsx
@@ -0,0 +1,31 @@
+import { notFound } from "next/navigation";
+
+import { Header } from "@/components/dashboard/header";
+import { MaintenanceList } from "@/components/status-page/maintenance-list";
+import { api } from "@/trpc/server";
+
+type Props = {
+ params: { domain: string };
+ searchParams: { [key: string]: string | string[] | undefined };
+};
+
+export default async function Page({ params }: Props) {
+ if (!params.domain) return notFound();
+
+ const page = await api.page.getPageBySlug.query({ slug: params.domain });
+ if (!page) return notFound();
+
+ return (
+ <div className="grid gap-8">
+ <Header
+ title={page.title}
+ description={page.description}
+ className="text-left"
+ />
+ <MaintenanceList
+ maintenances={page.maintenances}
+ monitors={page.monitors}
+ />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index 6647bb79b..74c5152de 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -8,6 +8,7 @@ import { MonitorList } from "@/components/status-page/monitor-list";
import { StatusCheck } from "@/components/status-page/status-check";
import { StatusReportList } from "@/components/status-page/status-report-list";
import { api } from "@/trpc/server";
+import { MaintenanceBanner } from "@/components/status-page/maintenance-banner";
type Props = {
params: { domain: string };
@@ -21,6 +22,12 @@ export default async function Page({ params }: Props) {
const page = await api.page.getPageBySlug.query({ slug: params.domain });
if (!page) return notFound();
+ const currentMaintenances = page.maintenances.filter(
+ (maintenance) =>
+ maintenance.to.getTime() > Date.now() &&
+ maintenance.from.getTime() < Date.now()
+ );
+
return (
<div className="mx-auto flex w-full flex-col gap-8">
<Header
@@ -31,18 +38,28 @@ export default async function Page({ params }: Props) {
<StatusCheck
statusReports={page.statusReports}
incidents={page.incidents}
+ maintenances={page.maintenances}
/>
+ {currentMaintenances.length ? (
+ <div className="grid w-full gap-3">
+ {currentMaintenances.map((maintenance) => (
+ <MaintenanceBanner key={maintenance.id} {...maintenance} />
+ ))}
+ </div>
+ ) : null}
<MonitorList
monitors={page.monitors}
statusReports={page.statusReports}
incidents={page.incidents}
+ maintenances={page.maintenances}
/>
<Separator />
<div className="grid gap-6">
<div>
- <h2 className="font-semibold text-xl">Latest Incidents</h2>
+ <h2 className="font-semibold text-xl">Last updates</h2>
<p className="text-muted-foreground text-sm">
- Incidents of the last 7 days or that have not been resolved yet.
+ Reports of the last 7 days or incidents that have not been resolved
+ yet.
</p>
</div>
<StatusReportList
diff --git a/apps/web/src/components/data-table/maintenance/columns.tsx b/apps/web/src/components/data-table/maintenance/columns.tsx
new file mode 100644
index 000000000..4b9958ed3
--- /dev/null
+++ b/apps/web/src/components/data-table/maintenance/columns.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import type { ColumnDef } from "@tanstack/react-table";
+
+import type { Maintenance } from "@openstatus/db/src/schema";
+
+import { DataTableRowActions } from "./data-table-row-actions";
+
+export const columns: ColumnDef<Maintenance>[] = [
+ {
+ accessorKey: "title",
+ header: "Title",
+ },
+ {
+ accessorKey: "message",
+ header: "Message",
+ cell: ({ row }) => {
+ return (
+ <p className="flex max-w-[125px] lg:max-w-[250px] xl:max-w-[350px]">
+ <span className="truncate">{row.getValue("message")}</span>
+ </p>
+ );
+ },
+ },
+ // missing: from, to
+ {
+ id: "actions",
+ cell: ({ row }) => {
+ return (
+ <div className="text-right">
+ <DataTableRowActions row={row} />
+ </div>
+ );
+ },
+ },
+];
diff --git a/apps/web/src/components/data-table/maintenance/data-table-row-actions.tsx b/apps/web/src/components/data-table/maintenance/data-table-row-actions.tsx
new file mode 100644
index 000000000..9b4cf0afe
--- /dev/null
+++ b/apps/web/src/components/data-table/maintenance/data-table-row-actions.tsx
@@ -0,0 +1,104 @@
+"use client";
+
+import type { Row } from "@tanstack/react-table";
+import { MoreHorizontal } from "lucide-react";
+import Link from "next/link";
+import { useRouter } from "next/navigation";
+import * as React from "react";
+
+import { selectMaintenanceSchema } from "@openstatus/db/src/schema";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@openstatus/ui";
+
+import { LoadingAnimation } from "@/components/loading-animation";
+import { toastAction } from "@/lib/toast";
+import { api } from "@/trpc/client";
+
+interface DataTableRowActionsProps<TData> {
+ row: Row<TData>;
+}
+
+export function DataTableRowActions<TData>({
+ row,
+}: DataTableRowActionsProps<TData>) {
+ const maintenance = selectMaintenanceSchema.parse(row.original);
+ const router = useRouter();
+ const [alertOpen, setAlertOpen] = React.useState(false);
+ const [isPending, startTransition] = React.useTransition();
+
+ async function onDelete() {
+ startTransition(async () => {
+ try {
+ if (!maintenance.id) return;
+ await api.maintenance.delete.mutate({ id: maintenance.id });
+ toastAction("deleted");
+ router.refresh();
+ setAlertOpen(false);
+ } catch {
+ toastAction("error");
+ }
+ });
+ }
+
+ return (
+ <AlertDialog open={alertOpen} onOpenChange={(value) => setAlertOpen(value)}>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
+ className="h-8 w-8 p-0 data-[state=open]:bg-accent"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreHorizontal className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <Link href={`./maintenances/${maintenance.id}/edit`}>
+ <DropdownMenuItem>Edit</DropdownMenuItem>
+ </Link>
+ <AlertDialogTrigger asChild>
+ <DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">
+ Delete
+ </DropdownMenuItem>
+ </AlertDialogTrigger>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This will permanently delete the
+ monitor.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ onClick={(e) => {
+ e.preventDefault();
+ onDelete();
+ }}
+ disabled={isPending}
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
+ >
+ {!isPending ? "Delete" : <LoadingAnimation />}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ );
+}
diff --git a/apps/web/src/components/data-table/maintenance/data-table.tsx b/apps/web/src/components/data-table/maintenance/data-table.tsx
new file mode 100644
index 000000000..d7e57ef59
--- /dev/null
+++ b/apps/web/src/components/data-table/maintenance/data-table.tsx
@@ -0,0 +1,81 @@
+"use client";
+
+import type { ColumnDef } from "@tanstack/react-table";
+import {
+ flexRender,
+ getCoreRowModel,
+ useReactTable,
+} from "@tanstack/react-table";
+import * as React from "react";
+
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@openstatus/ui";
+
+interface DataTableProps<TData, TValue> {
+ columns: ColumnDef<TData, TValue>[];
+ data: TData[];
+}
+
+export function DataTable<TData, TValue>({
+ columns,
+ data,
+}: DataTableProps<TData, TValue>) {
+ const table = useReactTable({
+ data,
+ columns,
+ getCoreRowModel: getCoreRowModel(),
+ });
+
+ return (
+ <div className="rounded-md border">
+ <Table>
+ <TableHeader className="bg-muted/50">
+ {table.getHeaderGroups().map((headerGroup) => (
+ <TableRow key={headerGroup.id} className="hover:bg-transparent">
+ {headerGroup.headers.map((header) => {
+ return (
+ <TableHead key={header.id}>
+ {header.isPlaceholder
+ ? null
+ : flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+ </TableHead>
+ );
+ })}
+ </TableRow>
+ ))}
+ </TableHeader>
+ <TableBody>
+ {table.getRowModel().rows?.length ? (
+ table.getRowModel().rows.map((row) => (
+ <TableRow
+ key={row.id}
+ data-state={row.getIsSelected() && "selected"}
+ >
+ {row.getVisibleCells().map((cell) => (
+ <TableCell key={cell.id}>
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+ </TableCell>
+ ))}
+ </TableRow>
+ ))
+ ) : (
+ <TableRow>
+ <TableCell colSpan={columns.length} className="h-24 text-center">
+ No results.
+ </TableCell>
+ </TableRow>
+ )}
+ </TableBody>
+ </Table>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/maintenance/form.tsx b/apps/web/src/components/forms/maintenance/form.tsx
new file mode 100644
index 000000000..5fefdec31
--- /dev/null
+++ b/apps/web/src/components/forms/maintenance/form.tsx
@@ -0,0 +1,120 @@
+"use client";
+
+import { zodResolver } from "@hookform/resolvers/zod";
+import { usePathname, useRouter } from "next/navigation";
+import * as React from "react";
+import { useTransition } from "react";
+import { useForm } from "react-hook-form";
+
+import { insertMaintenanceSchema } from "@openstatus/db/src/schema";
+import type { InsertMaintenance, Monitor } from "@openstatus/db/src/schema";
+import { Form } from "@openstatus/ui";
+
+import { toastAction } from "@/lib/toast";
+import { api } from "@/trpc/client";
+
+import {
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+} from "@/components/dashboard/tabs";
+
+import { SaveButton } from "../shared/save-button";
+import { General } from "./general";
+import { SectionConnect } from "./section-connect";
+
+interface Props {
+ defaultSection?: string;
+ defaultValues?: InsertMaintenance;
+ monitors?: Monitor[];
+ nextUrl?: string;
+ pageId: number;
+}
+
+export function MaintenanceForm({
+ defaultSection,
+ defaultValues,
+ monitors,
+ nextUrl,
+ pageId,
+}: Props) {
+ const form = useForm<InsertMaintenance>({
+ resolver: zodResolver(insertMaintenanceSchema),
+ defaultValues: {
+ ...defaultValues,
+ title: defaultValues?.title || "",
+ message: defaultValues?.message || "",
+ from: defaultValues?.from ? new Date(defaultValues.from) : new Date(),
+ to: defaultValues?.to
+ ? new Date(defaultValues.to)
+ : new Date(Date.now() + 1000 * 60 * 60),
+ pageId,
+ },
+ });
+ const router = useRouter();
+ const pathname = usePathname();
+ const [isPending, startTransition] = useTransition();
+
+ const onSubmit = async ({ ...props }: InsertMaintenance) => {
+ startTransition(async () => {
+ try {
+ if (defaultValues) {
+ await api.maintenance.update.mutate(props);
+ } else {
+ await api.maintenance.create.mutate(props);
+ }
+ toastAction("saved");
+ // otherwise, the form will stay dirty - keepValues is used to keep the current values in the form
+ form.reset({}, { keepValues: true });
+ if (nextUrl) {
+ router.push(nextUrl);
+ }
+ router.refresh();
+ } catch {
+ toastAction("error");
+ }
+ });
+ };
+
+ function onValueChange(value: string) {
+ // REMINDER: we are not merging the searchParams here
+ // we are just setting the section to allow refreshing the page
+ const params = new URLSearchParams();
+ params.set("section", value);
+ router.push(`${pathname}?${params.toString()}`);
+ }
+
+ console.log(form.formState.errors);
+
+ return (
+ <Form {...form}>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ form.handleSubmit(onSubmit)(e);
+ }}
+ className="grid w-full gap-6"
+ >
+ <General form={form} />
+ <Tabs
+ defaultValue={defaultSection}
+ className="w-full"
+ onValueChange={onValueChange}
+ >
+ <TabsList>
+ <TabsTrigger value="connect">Connect</TabsTrigger>
+ </TabsList>
+ <TabsContent value="connect">
+ <SectionConnect form={form} monitors={monitors} />
+ </TabsContent>
+ </Tabs>
+ <SaveButton
+ isPending={isPending}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(onSubmit)}
+ />
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/components/forms/maintenance/general.tsx b/apps/web/src/components/forms/maintenance/general.tsx
new file mode 100644
index 000000000..1f7f0b7b8
--- /dev/null
+++ b/apps/web/src/components/forms/maintenance/general.tsx
@@ -0,0 +1,110 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertMaintenance } from "@openstatus/db/src/schema";
+import {
+ DateTimePickerPopover,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ Textarea,
+} from "@openstatus/ui";
+
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ form: UseFormReturn<InsertMaintenance>;
+}
+
+export function General({ form }: Props) {
+ return (
+ <div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
+ <SectionHeader
+ title="Maintenance Information"
+ description="Give your users a heads up when you're doing maintenance."
+ />
+ <div className="flex w-full flex-col gap-4 sm:col-span-2">
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem className="w-full">
+ <FormLabel>Title</FormLabel>
+ <FormControl>
+ <Input placeholder="Database migration" {...field} />
+ </FormControl>
+ <FormDescription>Displayed on the status page.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="message"
+ render={({ field }) => (
+ <FormItem className="col-span-full">
+ <FormLabel>Message</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="We're doing some maintenance. We'll be back soon!"
+ {...field}
+ />
+ </FormControl>
+ <FormDescription>Give your users some context.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="grid grid-cols-2 gap-4">
+ <FormField
+ control={form.control}
+ name="from"
+ render={({ field }) => (
+ <FormItem className="flex w-full flex-col">
+ <FormLabel>From</FormLabel>
+ <DateTimePickerPopover
+ date={field.value ? new Date(field.value) : new Date()}
+ setDate={(date) => {
+ field.onChange(date);
+ }}
+ className="w-full"
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="to"
+ render={({ field }) => (
+ <FormItem className="flex w-full flex-col">
+ <FormLabel>To</FormLabel>
+ <DateTimePickerPopover
+ date={
+ field.value
+ ? new Date(field.value)
+ : new Date(Date.now() + 1000 * 60 * 60)
+ }
+ setDate={(date) => {
+ field.onChange(date);
+ }}
+ className="w-full"
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormDescription className="sm:-mt-2 col-span-full">
+ The date and time when the incident took place.
+ </FormDescription>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/maintenance/section-connect.tsx b/apps/web/src/components/forms/maintenance/section-connect.tsx
new file mode 100644
index 000000000..69a104ee4
--- /dev/null
+++ b/apps/web/src/components/forms/maintenance/section-connect.tsx
@@ -0,0 +1,90 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertMaintenance, Monitor } from "@openstatus/db/src/schema";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@openstatus/ui";
+
+import { CheckboxLabel } from "../shared/checkbox-label";
+
+interface Props {
+ form: UseFormReturn<InsertMaintenance>;
+ monitors?: Monitor[];
+}
+
+export function SectionConnect({ form, monitors }: Props) {
+ return (
+ <div className="grid w-full gap-4">
+ <div className="flex flex-col gap-3">
+ <FormField
+ control={form.control}
+ name="monitors"
+ render={() => (
+ <FormItem>
+ <div className="mb-4">
+ <FormLabel>Monitors</FormLabel>
+ <FormDescription>
+ Select the monitors that are affected by this maintenance.{" "}
+ <span className="font-medium">
+ We will not trigger any ping during that period.
+ </span>
+ </FormDescription>
+ </div>
+ <div className="grid grid-cols-1 grid-rows-1 gap-6 md:grid-cols-3 sm:grid-cols-2">
+ {monitors?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="monitors"
+ render={({ field }) => {
+ return (
+ <FormItem key={item.id} className="h-full w-full">
+ <FormControl className="w-full">
+ <CheckboxLabel
+ id={String(item.id)}
+ name="monitor"
+ 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
+ )
+ );
+ }}
+ >
+ {item.name}
+ </CheckboxLabel>
+ </FormControl>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ </div>
+ {!monitors || monitors.length === 0 ? (
+ <FormDescription>Missing monitors.</FormDescription>
+ ) : null}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsx
index b03de5ce5..2ceff714b 100644
--- a/apps/web/src/components/icons.tsx
+++ b/apps/web/src/components/icons.tsx
@@ -16,6 +16,7 @@ import {
FileClock,
Fingerprint,
Globe2,
+ Hammer,
Hourglass,
Image,
KeyRound,
@@ -66,6 +67,7 @@ export const Icons = {
table: Table,
"toy-brick": ToyBrick,
cog: Cog,
+ hammer: Hammer,
search: Search,
"search-check": SearchCheck,
fingerprint: Fingerprint,
diff --git a/apps/web/src/components/layout/app-sidebar.tsx b/apps/web/src/components/layout/app-sidebar.tsx
index 0a82e368c..e83568e62 100644
--- a/apps/web/src/components/layout/app-sidebar.tsx
+++ b/apps/web/src/components/layout/app-sidebar.tsx
@@ -1,12 +1,22 @@
"use client";
-import { useSelectedLayoutSegment } from "next/navigation";
+import { useParams, useSelectedLayoutSegment } from "next/navigation";
import type { Page } from "@/config/pages";
import { ProBanner } from "../billing/pro-banner";
import { AppLink } from "./app-link";
+function replacePlaceholders(
+ template: string,
+ values: { [key: string]: string }
+): string {
+ return template.replace(/\[([^\]]+)\]/g, (_, key) => {
+ return values[key] || `[${key}]`;
+ });
+}
+
export function AppSidebar({ page }: { page?: Page }) {
+ const params = useParams<Record<string, string>>();
const selectedSegment = useSelectedLayoutSegment();
if (!page) return null;
@@ -18,12 +28,13 @@ export function AppSidebar({ page }: { page?: Page }) {
{page?.title}
</p>
<ul className="grid gap-2">
- {page?.children?.map(({ title, segment, icon, disabled }) => {
+ {page?.children?.map(({ title, segment, icon, disabled, href }) => {
+ const prefix = `/app/${params.workspaceSlug}`;
return (
<li key={title} className="w-full">
<AppLink
label={title}
- href={`./${segment}`}
+ href={`${prefix}${replacePlaceholders(href, params)}`}
disabled={disabled}
active={segment === selectedSegment}
icon={icon}
diff --git a/apps/web/src/components/status-page/maintenance-banner.tsx b/apps/web/src/components/status-page/maintenance-banner.tsx
new file mode 100644
index 000000000..db71888e2
--- /dev/null
+++ b/apps/web/src/components/status-page/maintenance-banner.tsx
@@ -0,0 +1,21 @@
+import { isSameDay, format } from "date-fns";
+import { Hammer } from "lucide-react";
+
+import type { Maintenance } from "@openstatus/db/src/schema";
+import { Alert, AlertDescription, AlertTitle } from "@openstatus/ui";
+
+export function MaintenanceBanner(props: Maintenance) {
+ return (
+ <Alert className="border-blue-500/20 bg-blue-500/10">
+ <Hammer className="h-4 w-4" />
+ <AlertTitle>{props.title}</AlertTitle>
+ <AlertDescription>{props.message}</AlertDescription>
+ <AlertDescription className="mt-2 font-mono">
+ {format(props.from, "LLL dd, y HH:mm")} -{" "}
+ {isSameDay(props.from, props.to)
+ ? format(props.to, "HH:mm")
+ : format(props.to, "LLL dd, y HH:mm")}
+ </AlertDescription>
+ </Alert>
+ );
+}
diff --git a/apps/web/src/components/status-page/maintenance-list.tsx b/apps/web/src/components/status-page/maintenance-list.tsx
new file mode 100644
index 000000000..940b14be8
--- /dev/null
+++ b/apps/web/src/components/status-page/maintenance-list.tsx
@@ -0,0 +1,62 @@
+import { notEmpty } from "@/lib/utils";
+import type { Maintenance, PublicMonitor } from "@openstatus/db/src/schema";
+import { Badge } from "@openstatus/ui";
+import { format, isSameDay } from "date-fns";
+
+export function MaintenanceList({
+ maintenances,
+ monitors,
+}: {
+ maintenances: Maintenance[];
+ monitors: PublicMonitor[];
+}) {
+ if (!maintenances.length) {
+ return <EmptyState />;
+ }
+
+ return (
+ <ul className="grid gap-6">
+ {maintenances.map((maintenance) => {
+ const maintenanceMonitors = maintenance.monitors
+ ?.map((id) => {
+ return monitors.find((monitor) => monitor.id === id);
+ })
+ .filter(notEmpty);
+ return (
+ <li key={maintenance.id} className="grid gap-3">
+ <div>
+ <h3 className="font-semibold text-xl">{maintenance.title}</h3>
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="font-mono text-muted-foreground text-sm">
+ {format(maintenance.from, "LLL dd, y HH:mm")} -{" "}
+ {isSameDay(maintenance.from, maintenance.to)
+ ? format(maintenance.to, "HH:mm")
+ : format(maintenance.to, "LLL dd, y HH:mm")}
+ </span>
+ {maintenanceMonitors?.length ? (
+ <>
+ <span className="text-muted-foreground/50 text-xs">•</span>
+ {maintenanceMonitors.map((monitor) => (
+ <Badge key={monitor.id} variant="secondary">
+ {monitor.name}
+ </Badge>
+ ))}
+ </>
+ ) : null}
+ </div>
+ </div>
+ <p>{maintenance.message}</p>
+ </li>
+ );
+ })}
+ </ul>
+ );
+}
+
+function EmptyState() {
+ return (
+ <p className="text-center font-light text-muted-foreground text-sm">
+ No maintenances reported.
+ </p>
+ );
+}
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
index db2bfd5d6..24d253030 100644
--- a/apps/web/src/components/status-page/monitor-list.tsx
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -2,6 +2,7 @@ import type { z } from "zod";
import type {
Incident,
+ Maintenance,
PublicMonitor,
selectPublicStatusReportSchemaWithRelation,
} from "@openstatus/db/src/schema";
@@ -12,21 +13,27 @@ export const MonitorList = ({
monitors,
statusReports,
incidents,
+ maintenances,
}: {
monitors: PublicMonitor[];
statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
incidents: Incident[];
+ maintenances: Maintenance[];
}) => {
+ console.log({ maintenances });
return (
<div className="grid gap-4">
{monitors.map((monitor, _index) => {
const monitorStatusReport = statusReports.filter((statusReport) =>
statusReport.monitorsToStatusReports.some(
- (i) => i.monitor.id === monitor.id,
- ),
+ (i) => i.monitor.id === monitor.id
+ )
);
const monitorIncidents = incidents.filter(
- (incident) => incident.monitorId === monitor.id,
+ (incident) => incident.monitorId === monitor.id
+ );
+ const monitorMaintenances = maintenances.filter((maintenance) =>
+ maintenance.monitors?.includes(monitor.id)
);
return (
<Monitor
@@ -34,6 +41,7 @@ export const MonitorList = ({
monitor={monitor}
statusReports={monitorStatusReport}
incidents={monitorIncidents}
+ maintenances={monitorMaintenances}
/>
);
})}
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
index 93db6ac71..9477af507 100644
--- a/apps/web/src/components/status-page/monitor.tsx
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -2,6 +2,7 @@ import type { z } from "zod";
import type {
Incident,
+ Maintenance,
PublicMonitor,
selectPublicStatusReportSchemaWithRelation,
} from "@openstatus/db/src/schema";
@@ -16,10 +17,12 @@ export const Monitor = async ({
monitor,
statusReports,
incidents,
+ maintenances,
}: {
monitor: PublicMonitor;
statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
incidents: Incident[];
+ maintenances: Maintenance[];
}) => {
const data = await tb.endpointStatusPeriod("45d")({
monitorId: String(monitor.id),
@@ -34,6 +37,7 @@ export const Monitor = async ({
data={data}
reports={statusReports}
incidents={incidents}
+ maintenances={maintenances}
{...monitor}
/>
);
diff --git a/apps/web/src/components/status-page/status-check.tsx b/apps/web/src/components/status-page/status-check.tsx
index 945217911..4a1ef7f78 100644
--- a/apps/web/src/components/status-page/status-check.tsx
+++ b/apps/web/src/components/status-page/status-check.tsx
@@ -1,4 +1,8 @@
-import type { Incident, StatusReport } from "@openstatus/db/src/schema";
+import type {
+ Incident,
+ Maintenance,
+ StatusReport,
+} from "@openstatus/db/src/schema";
import type { StatusVariant } from "@openstatus/tracker";
import { Tracker } from "@openstatus/tracker";
@@ -9,11 +13,13 @@ import { Icons } from "../icons";
export async function StatusCheck({
statusReports,
incidents,
+ maintenances,
}: {
statusReports: StatusReport[];
incidents: Incident[];
+ maintenances: Maintenance[];
}) {
- const tracker = new Tracker({ statusReports, incidents });
+ const tracker = new Tracker({ statusReports, incidents, maintenances });
const className = tracker.currentClassName;
const details = tracker.currentDetails;
@@ -40,6 +46,9 @@ export function StatusIcon({ variant }: { variant: StatusVariant }) {
const AlertTriangleIcon = Icons["alert-triangle"];
return <AlertTriangleIcon className="h-5 w-5 text-background" />;
}
+ if (variant === "maintenance") {
+ return <Icons.hammer className="h-5 w-5 text-background" />;
+ }
if (variant === "degraded") {
return <Icons.minus className="h-5 w-5 text-background" />;
}
diff --git a/apps/web/src/components/status-page/status-report-list.tsx b/apps/web/src/components/status-page/status-report-list.tsx
index 9598cc952..498a595d5 100644
--- a/apps/web/src/components/status-page/status-report-list.tsx
+++ b/apps/web/src/components/status-page/status-report-list.tsx
@@ -34,31 +34,29 @@ export const StatusReportList = ({
return b.updatedAt.getTime() - a.updatedAt.getTime();
});
+ if (!reports.length) {
+ return <EmptyState />;
+ }
+
return (
- <>
- {reports?.length > 0 ? (
- <div className="grid gap-8">
- {reports.map((report, i) => {
- const affectedMonitors = report.monitorsToStatusReports
- .map(({ monitorId }) => {
- const monitor = monitors.find(({ id }) => monitorId === id);
- return monitor || undefined;
- })
- .filter(notEmpty);
- const isLast = reports.length - 1 === i;
+ <div className="grid gap-8">
+ {reports.map((report, i) => {
+ const affectedMonitors = report.monitorsToStatusReports
+ .map(({ monitorId }) => {
+ const monitor = monitors.find(({ id }) => monitorId === id);
+ return monitor || undefined;
+ })
+ .filter(notEmpty);
+ const isLast = reports.length - 1 === i;
- return (
- <div key={report.id} className="grid gap-6">
- <StatusReport monitors={affectedMonitors} report={report} />
- {!isLast ? <Separator /> : null}
- </div>
- );
- })}
- </div>
- ) : (
- <EmptyState />
- )}
- </>
+ return (
+ <div key={report.id} className="grid gap-6">
+ <StatusReport monitors={affectedMonitors} report={report} />
+ {!isLast ? <Separator /> : null}
+ </div>
+ );
+ })}
+ </div>
);
};
diff --git a/apps/web/src/components/status-page/status-report.tsx b/apps/web/src/components/status-page/status-report.tsx
index e239f880e..78719f6f3 100644
--- a/apps/web/src/components/status-page/status-report.tsx
+++ b/apps/web/src/components/status-page/status-report.tsx
@@ -15,6 +15,7 @@ import { Badge, Button } from "@openstatus/ui";
import { setPrefixUrl } from "@/app/status-page/[domain]/utils";
import { StatusBadge } from "../status-update/status-badge";
import { ProcessMessage } from "./process-message";
+import { cn } from "@/lib/utils";
function StatusReport({
report,
@@ -38,7 +39,7 @@ function StatusReportHeader({ report }: { report: StatusReportWithUpdates }) {
const params = useParams<{ domain: string }>();
return (
<div className="flex items-center gap-2">
- <h3 className="font-semibold text-2xl">{report.title}</h3>
+ <h3 className="font-semibold text-xl">{report.title}</h3>
<Button
variant="ghost"
size="icon"
@@ -56,14 +57,16 @@ function StatusReportHeader({ report }: { report: StatusReportWithUpdates }) {
function StatusReportDescription({
report,
monitors,
+ className,
}: {
report: StatusReportWithUpdates;
monitors: PublicMonitor[];
+ className?: string;
}) {
const firstReport =
report.statusReportUpdates[report.statusReportUpdates.length - 1];
return (
- <div className="flex flex-wrap items-center gap-2">
+ <div className={cn("flex flex-wrap items-center gap-2", className)}>
<p className="text-muted-foreground">
{format(firstReport.date || new Date(), "LLL dd, y HH:mm")}
</p>
diff --git a/apps/web/src/components/tracker/tracker.tsx b/apps/web/src/components/tracker/tracker.tsx
index 6136e20d9..dfa6bea5b 100644
--- a/apps/web/src/components/tracker/tracker.tsx
+++ b/apps/web/src/components/tracker/tracker.tsx
@@ -8,6 +8,7 @@ import * as React from "react";
import type {
Incident,
+ Maintenance,
StatusReport,
StatusReportUpdate,
} from "@openstatus/db/src/schema";
@@ -50,6 +51,7 @@ interface TrackerProps {
description?: string;
reports?: (StatusReport & { statusReportUpdates: StatusReportUpdate[] })[];
incidents?: Incident[];
+ maintenances?: Maintenance[];
}
export function Tracker({
@@ -58,8 +60,14 @@ export function Tracker({
description,
reports,
incidents,
+ maintenances,
}: TrackerProps) {
- const tracker = new OSTracker({ data, statusReports: reports, incidents });
+ const tracker = new OSTracker({
+ data,
+ statusReports: reports,
+ incidents,
+ maintenances,
+ });
const uptime = tracker.totalUptime;
const isMissing = tracker.isDataMissing;
@@ -142,7 +150,7 @@ export const Bar = ({
<div
className={cn(
rootClassName,
- "h-auto w-1 flex-none rounded-full",
+ "h-auto w-1 flex-none rounded-full"
)}
/>
<div className="grid flex-1 gap-1">
@@ -237,7 +245,7 @@ export function DowntimeText({
Down for{" "}
{formatDuration(
{ minutes, hours, days },
- { format: ["days", "hours", "minutes", "seconds"], zero: false },
+ { format: ["days", "hours", "minutes", "seconds"], zero: false }
)}
</p>
);
diff --git a/apps/web/src/config/pages.ts b/apps/web/src/config/pages.ts
index 6a4dfb3fb..aea5518d0 100644
--- a/apps/web/src/config/pages.ts
+++ b/apps/web/src/config/pages.ts
@@ -101,6 +101,13 @@ export const statusPagesPagesConfig: Page[] = [
icon: "users",
segment: "subscribers",
},
+ {
+ title: "Maintenance",
+ description: "Where you can see all the maintenance.",
+ href: "/status-pages/[id]/maintenances",
+ icon: "hammer",
+ segment: "maintenances",
+ },
];
const incidentPagesConfig: Page[] = [
@@ -240,7 +247,7 @@ export const marketingPagesConfig = [
export function getPageBySegment(
segment: string | string[],
- currentPage: readonly Page[] = pagesConfig,
+ currentPage: readonly Page[] = pagesConfig
): Page | undefined {
if (typeof segment === "string") {
const page = currentPage.find((page) => page.segment === segment);
diff --git a/apps/web/src/content/changelog/maintenance-status.mdx b/apps/web/src/content/changelog/maintenance-status.mdx
new file mode 100644
index 000000000..607161538
--- /dev/null
+++ b/apps/web/src/content/changelog/maintenance-status.mdx
@@ -0,0 +1,12 @@
+---
+title: Maintenance status
+description: Show your users that you're performing maintenance.
+image: /assets/changelog/maintenance-status.png
+publishedAt: 2024-06-09
+---
+
+You can now set your status to _Under Maintenance_ to inform your users that you're performing maintenance. You'll be able to set the start and end times for the maintenance period. During this time, we will pause the connected monitors and suppress any notifications.
+
+To create a maintenance, go to the corresponding status page and click the 'Maintenance' sub navigation. From there, you can create a new maintenance status, including `title` and `description`.
+
+The users will be able to see all maintenances under a new tab on the status page.
\ No newline at end of file
diff --git a/apps/web/src/lib/timezone.ts b/apps/web/src/lib/timezone.ts
index 4dcc2312a..8f0cdbaaf 100644
--- a/apps/web/src/lib/timezone.ts
+++ b/apps/web/src/lib/timezone.ts
@@ -38,6 +38,18 @@ export function getServerTimezoneFormat() {
return format(new Date(), "LLL dd, y HH:mm:ss zzz", { timeZone: "UTC" });
}
+export function formatDate(date: Date) {
+ return format(date, "LLL dd, y", { timeZone: "UTC" });
+}
+
+export function formatDateTime(date: Date) {
+ return format(date, "LLL dd, y HH:mm:ss zzz", { timeZone: "UTC" });
+}
+
+export function formatTime(date: Date) {
+ return format(date, "HH:mm:ss zzz", { timeZone: "UTC" });
+}
+
/**
* All supported browser / node timezones
*/
@@ -82,7 +94,7 @@ export function getClosestTimezone(defaultTimezone?: string) {
}
return prev;
},
- { timezone: "UTC", minDifference: Number.POSITIVE_INFINITY },
+ { timezone: "UTC", minDifference: Number.POSITIVE_INFINITY }
);
return closestTimezone.timezone as keyof typeof timeDifferences;
diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts
index 81f46096e..7e4efc913 100644
--- a/apps/web/src/lib/utils.ts
+++ b/apps/web/src/lib/utils.ts
@@ -19,6 +19,10 @@ export function formatDateTime(date: Date) {
return format(date, "LLL dd, y HH:mm:ss");
}
+export function formatTime(date: Date) {
+ return format(date, "HH:mm:ss");
+}
+
export function formatDuration(ms: number) {
let v = ms;
if (ms < 0) v = -ms;
@@ -36,7 +40,7 @@ export function formatDuration(ms: number) {
}
export function notEmpty<TValue>(
- value: TValue | null | undefined,
+ value: TValue | null | undefined
): value is TValue {
return value !== null && value !== undefined;
}
@@ -65,7 +69,7 @@ export function manipulateDate(
date?: {
from: Date | undefined;
to?: Date | undefined;
- } | null,
+ } | null
) {
const isToDateMidnight = String(date?.to?.getTime()).endsWith("00000");
diff --git a/packages/api/src/edge.ts b/packages/api/src/edge.ts
index 329527f21..03487f909 100644
--- a/packages/api/src/edge.ts
+++ b/packages/api/src/edge.ts
@@ -2,6 +2,7 @@ import { domainRouter } from "./router/domain";
import { incidentRouter } from "./router/incident";
import { integrationRouter } from "./router/integration";
import { invitationRouter } from "./router/invitation";
+import { maintenanceRouter } from "./router/maintenance";
import { monitorRouter } from "./router/monitor";
import { monitorTagRouter } from "./router/monitorTag";
import { notificationRouter } from "./router/notification";
@@ -28,4 +29,5 @@ export const edgeRouter = createTRPCRouter({
pageSubscriber: pageSubscriberRouter,
tinybird: tinybirdRouter,
monitorTag: monitorTagRouter,
+ maintenance: maintenanceRouter,
});
diff --git a/packages/api/src/router/maintenance.ts b/packages/api/src/router/maintenance.ts
new file mode 100644
index 000000000..6091a4e5a
--- /dev/null
+++ b/packages/api/src/router/maintenance.ts
@@ -0,0 +1,163 @@
+import { z } from "zod";
+
+import { and, eq, inArray } from "@openstatus/db";
+import {
+ insertMaintenanceSchema,
+ maintenance,
+ maintenancesToMonitors,
+ selectMaintenanceSchema,
+} from "@openstatus/db/src/schema";
+
+import { createTRPCRouter, protectedProcedure } from "../trpc";
+import { TRPCError } from "@trpc/server";
+
+export const maintenanceRouter = createTRPCRouter({
+ create: protectedProcedure
+ .input(insertMaintenanceSchema)
+ .mutation(async (opts) => {
+ const _maintenance = await opts.ctx.db
+ .insert(maintenance)
+ .values({ ...opts.input, workspaceId: opts.ctx.workspace.id })
+ .returning()
+ .get();
+
+ if (opts.input.monitors?.length) {
+ await opts.ctx.db
+ .insert(maintenancesToMonitors)
+ .values(
+ opts.input.monitors.map((monitorId) => ({
+ maintenanceId: _maintenance.id,
+ monitorId,
+ }))
+ )
+ .returning()
+ .get();
+ }
+
+ return _maintenance;
+ }),
+ getById: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async (opts) => {
+ const _maintenance = await opts.ctx.db
+ .select()
+ .from(maintenance)
+ .where(
+ and(
+ eq(maintenance.id, opts.input.id),
+ eq(maintenance.workspaceId, opts.ctx.workspace.id)
+ )
+ )
+ .get();
+
+ if (!_maintenance) return undefined;
+ // TODO: make it work with `with: { maintenacesToMonitors: true }`
+ const _monitors = await opts.ctx.db
+ .select()
+ .from(maintenancesToMonitors)
+ .where(eq(maintenancesToMonitors.maintenanceId, _maintenance.id))
+ .all();
+ return { ..._maintenance, monitors: _monitors.map((m) => m.monitorId) };
+ }),
+ getByWorkspace: protectedProcedure.query(async (opts) => {
+ const _maintenances = await opts.ctx.db
+ .select()
+ .from(maintenance)
+ .where(eq(maintenance.workspaceId, opts.ctx.workspace.id))
+ .all();
+ return _maintenances;
+ }),
+ getByPage: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async (opts) => {
+ const _maintenances = await opts.ctx.db
+ .select()
+ .from(maintenance)
+ .where(
+ and(
+ eq(maintenance.pageId, opts.input.id),
+ eq(maintenance.workspaceId, opts.ctx.workspace.id)
+ )
+ )
+ .all();
+ // TODO:
+ return _maintenances;
+ }),
+ update: protectedProcedure
+ .input(insertMaintenanceSchema)
+ .mutation(async (opts) => {
+ if (!opts.input.id) {
+ throw new TRPCError({ code: "BAD_REQUEST", message: "id is required" });
+ }
+
+ const _maintenance = await opts.ctx.db
+ .update(maintenance)
+ .set({ ...opts.input, workspaceId: opts.ctx.workspace.id })
+ .where(
+ and(
+ eq(maintenance.id, opts.input.id),
+ eq(maintenance.workspaceId, opts.ctx.workspace.id)
+ )
+ )
+ .returning()
+ .get();
+
+ const _maintenancesToMonitors = await opts.ctx.db
+ .select()
+ .from(maintenancesToMonitors)
+ .where(eq(maintenancesToMonitors.maintenanceId, _maintenance.id))
+ .all();
+
+ const _monitorsIds = _maintenancesToMonitors.map(
+ ({ monitorId }) => monitorId
+ );
+
+ const added = opts.input.monitors?.filter(
+ (monitor) => !_monitorsIds.includes(monitor)
+ );
+
+ if (added?.length) {
+ await opts.ctx.db
+ .insert(maintenancesToMonitors)
+ .values(
+ added.map((monitorId) => ({
+ maintenanceId: _maintenance.id,
+ monitorId,
+ }))
+ )
+ .returning()
+ .get();
+ }
+
+ const removed = _monitorsIds.filter(
+ (monitor) => !opts.input.monitors?.includes(monitor)
+ );
+
+ if (removed?.length) {
+ await opts.ctx.db
+ .delete(maintenancesToMonitors)
+ .where(
+ and(
+ eq(maintenancesToMonitors.maintenanceId, _maintenance.id),
+ inArray(maintenancesToMonitors.monitorId, removed)
+ )
+ )
+ .run();
+ }
+
+ return _maintenance;
+ }),
+ delete: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .mutation(async (opts) => {
+ return await opts.ctx.db
+ .delete(maintenance)
+ .where(
+ and(
+ eq(maintenance.id, opts.input.id),
+ eq(maintenance.workspaceId, opts.ctx.workspace.id)
+ )
+ )
+ .returning();
+ }),
+});
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 13ec400ed..dd99d94db 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -181,7 +181,6 @@ export const monitorRouter = createTRPCRouter({
.safeParse(_monitor);
if (!parsedMonitor.success) {
- console.log(parsedMonitor.error);
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not allowed to access the monitor.",
@@ -451,6 +450,48 @@ export const monitorRouter = createTRPCRouter({
.parse(monitors);
}),
+ getMonitorsByPageId: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async (opts) => {
+ const _page = await opts.ctx.db.query.page.findFirst({
+ where: and(
+ eq(page.id, opts.input.id),
+ eq(page.workspaceId, opts.ctx.workspace.id)
+ ),
+ });
+
+ if (!_page) return undefined;
+
+ const monitors = await opts.ctx.db.query.monitor.findMany({
+ where: and(
+ eq(monitor.workspaceId, opts.ctx.workspace.id),
+ isNull(monitor.deletedAt)
+ ),
+ with: {
+ monitorTagsToMonitors: { with: { monitorTag: true } },
+ monitorsToPages: {
+ where: eq(monitorsToPages.pageId, _page.id),
+ },
+ },
+ });
+
+ return z
+ .array(
+ selectMonitorSchema.extend({
+ monitorTagsToMonitors: z
+ .array(z.object({ monitorTag: selectMonitorTagSchema }))
+ .default([]),
+ })
+ )
+ .parse(
+ monitors.filter((monitor) =>
+ monitor.monitorsToPages
+ .map(({ pageId }) => pageId)
+ .includes(_page.id)
+ )
+ );
+ }),
+
toggleMonitorActive: protectedProcedure
.input(z.object({ id: z.number() }))
.mutation(async (opts) => {
diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.ts
index aae002dfa..c8e4c8762 100644
--- a/packages/api/src/router/page.ts
+++ b/packages/api/src/router/page.ts
@@ -5,6 +5,7 @@ import { and, eq, inArray, isNull, or, sql } from "@openstatus/db";
import {
incidentTable,
insertPageSchema,
+ maintenance,
monitor,
monitorsToPages,
monitorsToStatusReport,
@@ -65,7 +66,7 @@ export const pageRouter = createTRPCRouter({
where: and(
inArray(monitor.id, monitorIds),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
});
@@ -95,7 +96,7 @@ export const pageRouter = createTRPCRouter({
const firstPage = await opts.ctx.db.query.page.findFirst({
where: and(
eq(page.id, opts.input.id),
- eq(page.workspaceId, opts.ctx.workspace.id),
+ eq(page.workspaceId, opts.ctx.workspace.id)
),
with: {
monitorsToPages: {
@@ -132,8 +133,8 @@ export const pageRouter = createTRPCRouter({
.where(
and(
eq(page.id, pageInput.id),
- eq(page.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(page.workspaceId, opts.ctx.workspace.id)
+ )
)
.returning()
.get();
@@ -144,7 +145,7 @@ export const pageRouter = createTRPCRouter({
where: and(
inArray(monitor.id, monitorIds),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
});
@@ -173,8 +174,8 @@ export const pageRouter = createTRPCRouter({
.where(
and(
inArray(monitorsToPages.monitorId, removedMonitors),
- eq(monitorsToPages.pageId, currentPage.id),
- ),
+ eq(monitorsToPages.pageId, currentPage.id)
+ )
);
}
@@ -202,8 +203,8 @@ export const pageRouter = createTRPCRouter({
.where(
and(
eq(page.id, opts.input.id),
- eq(page.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(page.workspaceId, opts.ctx.workspace.id)
+ )
)
.run();
}),
@@ -245,12 +246,12 @@ export const pageRouter = createTRPCRouter({
.leftJoin(monitor, eq(monitorsToPages.monitorId, monitor.id))
.where(
// make sur only active monitors are returned!
- and(eq(monitorsToPages.pageId, result.id), eq(monitor.active, true)),
+ and(eq(monitorsToPages.pageId, result.id), eq(monitor.active, true))
)
.all();
const monitorsId = monitorsToPagesResult.map(
- ({ monitors_to_pages }) => monitors_to_pages.monitorId,
+ ({ monitors_to_pages }) => monitors_to_pages.monitorId
);
const monitorsToStatusReportResult =
@@ -269,15 +270,15 @@ export const pageRouter = createTRPCRouter({
.all();
const monitorStatusReportIds = monitorsToStatusReportResult.map(
- ({ statusReportId }) => statusReportId,
+ ({ statusReportId }) => statusReportId
);
const pageStatusReportIds = statusReportsToPagesResult.map(
- ({ statusReportId }) => statusReportId,
+ ({ statusReportId }) => statusReportId
);
const statusReportIds = Array.from(
- new Set([...monitorStatusReportIds, ...pageStatusReportIds]),
+ new Set([...monitorStatusReportIds, ...pageStatusReportIds])
);
const statusReports =
@@ -304,8 +305,8 @@ export const pageRouter = createTRPCRouter({
and(
inArray(monitor.id, monitorsId),
eq(monitor.active, true),
- isNull(monitor.deletedAt),
- ), // REMINDER: this is hardcoded
+ isNull(monitor.deletedAt)
+ ) // REMINDER: this is hardcoded
)
.all()
: [];
@@ -318,12 +319,18 @@ export const pageRouter = createTRPCRouter({
.where(
inArray(
incidentTable.monitorId,
- monitors.map((m) => m.id),
- ),
+ monitors.map((m) => m.id)
+ )
)
.all()
: [];
+ const maintenances = await opts.ctx.db.query.maintenance.findMany({
+ where: eq(maintenance.pageId, result.id),
+ with: { maintenancesToMonitors: true },
+ orderBy: (maintenances, { desc }) => desc(maintenances.from),
+ });
+
return selectPublicPageSchemaWithRelation.parse({
...result,
// TODO: improve performance and move into SQLite query
@@ -338,6 +345,10 @@ export const pageRouter = createTRPCRouter({
}),
incidents,
statusReports,
+ maintenances: maintenances.map((m) => ({
+ ...m,
+ monitors: m.maintenancesToMonitors.map((m) => m.monitorId),
+ })),
workspacePlan: workspaceResult?.plan,
});
}),
@@ -348,7 +359,7 @@ export const pageRouter = createTRPCRouter({
// had filter on some words we want to keep for us
if (
["api", "app", "www", "docs", "checker", "time", "help"].includes(
- opts.input.slug,
+ opts.input.slug
)
) {
return false;
@@ -361,7 +372,7 @@ export const pageRouter = createTRPCRouter({
addCustomDomain: protectedProcedure
.input(
- z.object({ customDomain: z.string().toLowerCase(), pageId: z.number() }),
+ z.object({ customDomain: z.string().toLowerCase(), pageId: z.number() })
)
.mutation(async (opts) => {
// TODO Add some check ?
diff --git a/packages/db/drizzle/0031_lowly_gabe_jones.sql b/packages/db/drizzle/0031_lowly_gabe_jones.sql
new file mode 100644
index 000000000..2ed719ac8
--- /dev/null
+++ b/packages/db/drizzle/0031_lowly_gabe_jones.sql
@@ -0,0 +1,22 @@
+CREATE TABLE `maintenance` (
+ `id` integer PRIMARY KEY NOT NULL,
+ `title` text(256) NOT NULL,
+ `message` text NOT NULL,
+ `from` integer NOT NULL,
+ `to` integer NOT NULL,
+ `workspace_id` integer,
+ `page_id` integer,
+ `created_at` integer DEFAULT (strftime('%s', 'now')),
+ `updated_at` integer DEFAULT (strftime('%s', 'now')),
+ FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE no action,
+ FOREIGN KEY (`page_id`) REFERENCES `page`(`id`) ON UPDATE no action ON DELETE no action
+);
+--> statement-breakpoint
+CREATE TABLE `maintenance_to_monitor` (
+ `monitor_id` integer NOT NULL,
+ `maintenance_id` integer NOT NULL,
+ `created_at` integer DEFAULT (strftime('%s', 'now')),
+ PRIMARY KEY(`maintenance_id`, `monitor_id`),
+ FOREIGN KEY (`monitor_id`) REFERENCES `monitor`(`id`) ON UPDATE no action ON DELETE cascade,
+ FOREIGN KEY (`maintenance_id`) REFERENCES `maintenance`(`id`) ON UPDATE no action ON DELETE cascade
+);
diff --git a/packages/db/drizzle/meta/0031_snapshot.json b/packages/db/drizzle/meta/0031_snapshot.json
new file mode 100644
index 000000000..526ae42b4
--- /dev/null
+++ b/packages/db/drizzle/meta/0031_snapshot.json
@@ -0,0 +1,2125 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "afc5bf87-9bfd-4753-af9f-edbf7b3351ba",
+ "prevId": "baadea64-aa8c-4b6f-b0e5-55ca15fc05b0",
+ "tables": {
+ "status_report_to_monitors": {
+ "name": "status_report_to_monitors",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status_report_id": {
+ "name": "status_report_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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "status_report_to_monitors_monitor_id_monitor_id_fk": {
+ "name": "status_report_to_monitors_monitor_id_monitor_id_fk",
+ "tableFrom": "status_report_to_monitors",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "status_report_to_monitors_status_report_id_status_report_id_fk": {
+ "name": "status_report_to_monitors_status_report_id_status_report_id_fk",
+ "tableFrom": "status_report_to_monitors",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "status_report_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "status_report_to_monitors_monitor_id_status_report_id_pk": {
+ "columns": [
+ "monitor_id",
+ "status_report_id"
+ ],
+ "name": "status_report_to_monitors_monitor_id_status_report_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "status_reports_to_pages": {
+ "name": "status_reports_to_pages",
+ "columns": {
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status_report_id": {
+ "name": "status_report_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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "status_reports_to_pages_page_id_page_id_fk": {
+ "name": "status_reports_to_pages_page_id_page_id_fk",
+ "tableFrom": "status_reports_to_pages",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "status_reports_to_pages_status_report_id_status_report_id_fk": {
+ "name": "status_reports_to_pages_status_report_id_status_report_id_fk",
+ "tableFrom": "status_reports_to_pages",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "status_report_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "status_reports_to_pages_page_id_status_report_id_pk": {
+ "columns": [
+ "page_id",
+ "status_report_id"
+ ],
+ "name": "status_reports_to_pages_page_id_status_report_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "status_report": {
+ "name": "status_report",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "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": {
+ "status_report_workspace_id_workspace_id_fk": {
+ "name": "status_report_workspace_id_workspace_id_fk",
+ "tableFrom": "status_report",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "status_report_update": {
+ "name": "status_report_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
+ },
+ "status_report_id": {
+ "name": "status_report_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": {
+ "status_report_update_status_report_id_status_report_id_fk": {
+ "name": "status_report_update_status_report_id_status_report_id_fk",
+ "tableFrom": "status_report_update",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "status_report_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "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
+ },
+ "password": {
+ "name": "password",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "password_protected": {
+ "name": "password_protected",
+ "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",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "periodicity": {
+ "name": "periodicity",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "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",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'GET'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "assertions": {
+ "name": "assertions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "public": {
+ "name": "public",
+ "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'))"
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "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
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "order": {
+ "name": "order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ }
+ },
+ "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"
+ ],
+ "name": "monitors_to_pages_monitor_id_page_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "account": {
+ "name": "account",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider_account_id": {
+ "name": "provider_account_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "token_type": {
+ "name": "token_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "session_state": {
+ "name": "session_state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "account_user_id_user_id_fk": {
+ "name": "account_user_id_user_id_fk",
+ "tableFrom": "account",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "account_provider_provider_account_id_pk": {
+ "columns": [
+ "provider",
+ "provider_account_id"
+ ],
+ "name": "account_provider_provider_account_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "session": {
+ "name": "session",
+ "columns": {
+ "session_token": {
+ "name": "session_token",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires": {
+ "name": "expires",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "session_user_id_user_id_fk": {
+ "name": "session_user_id_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "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": "''"
+ },
+ "photo_url": {
+ "name": "photo_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "emailVerified": {
+ "name": "emailVerified",
+ "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": {
+ "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
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'member'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "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"
+ ],
+ "name": "users_to_workspaces_user_id_workspace_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "verification_token": {
+ "name": "verification_token",
+ "columns": {
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires": {
+ "name": "expires",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "verification_token_identifier_token_pk": {
+ "columns": [
+ "identifier",
+ "token"
+ ],
+ "name": "verification_token_identifier_token_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "page_subscriber": {
+ "name": "page_subscriber",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "accepted_at": {
+ "name": "accepted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "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": {
+ "page_subscriber_page_id_page_id_fk": {
+ "name": "page_subscriber_page_id_page_id_fk",
+ "tableFrom": "page_subscriber",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "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",
+ "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'))"
+ },
+ "dsn": {
+ "name": "dsn",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "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
+ },
+ "workspace_id_dsn_unique": {
+ "name": "workspace_id_dsn_unique",
+ "columns": [
+ "id",
+ "dsn"
+ ],
+ "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
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "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"
+ ],
+ "name": "notifications_to_monitors_monitor_id_notification_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "monitor_status": {
+ "name": "monitor_status",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "region": {
+ "name": "region",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "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": {
+ "monitor_status_idx": {
+ "name": "monitor_status_idx",
+ "columns": [
+ "monitor_id",
+ "region"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "monitor_status_monitor_id_monitor_id_fk": {
+ "name": "monitor_status_monitor_id_monitor_id_fk",
+ "tableFrom": "monitor_status",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "monitor_status_monitor_id_region_pk": {
+ "columns": [
+ "monitor_id",
+ "region"
+ ],
+ "name": "monitor_status_monitor_id_region_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "invitation": {
+ "name": "invitation",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'member'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "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'))"
+ },
+ "accepted_at": {
+ "name": "accepted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "incident": {
+ "name": "incident",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "summary": {
+ "name": "summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'triage'"
+ },
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "acknowledged_at": {
+ "name": "acknowledged_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "acknowledged_by": {
+ "name": "acknowledged_by",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "resolved_at": {
+ "name": "resolved_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "resolved_by": {
+ "name": "resolved_by",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "incident_screenshot_url": {
+ "name": "incident_screenshot_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "recovery_screenshot_url": {
+ "name": "recovery_screenshot_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "auto_resolved": {
+ "name": "auto_resolved",
+ "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": {
+ "incident_monitor_id_started_at_unique": {
+ "name": "incident_monitor_id_started_at_unique",
+ "columns": [
+ "monitor_id",
+ "started_at"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "incident_monitor_id_monitor_id_fk": {
+ "name": "incident_monitor_id_monitor_id_fk",
+ "tableFrom": "incident",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set default",
+ "onUpdate": "no action"
+ },
+ "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"
+ },
+ "incident_acknowledged_by_user_id_fk": {
+ "name": "incident_acknowledged_by_user_id_fk",
+ "tableFrom": "incident",
+ "tableTo": "user",
+ "columnsFrom": [
+ "acknowledged_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "incident_resolved_by_user_id_fk": {
+ "name": "incident_resolved_by_user_id_fk",
+ "tableFrom": "incident",
+ "tableTo": "user",
+ "columnsFrom": [
+ "resolved_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitor_tag": {
+ "name": "monitor_tag",
+ "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
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitor_tag_workspace_id_workspace_id_fk": {
+ "name": "monitor_tag_workspace_id_workspace_id_fk",
+ "tableFrom": "monitor_tag",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitor_tag_to_monitor": {
+ "name": "monitor_tag_to_monitor",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "monitor_tag_id": {
+ "name": "monitor_tag_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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitor_tag_to_monitor_monitor_id_monitor_id_fk": {
+ "name": "monitor_tag_to_monitor_monitor_id_monitor_id_fk",
+ "tableFrom": "monitor_tag_to_monitor",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk": {
+ "name": "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk",
+ "tableFrom": "monitor_tag_to_monitor",
+ "tableTo": "monitor_tag",
+ "columnsFrom": [
+ "monitor_tag_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk": {
+ "columns": [
+ "monitor_id",
+ "monitor_tag_id"
+ ],
+ "name": "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk"
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "application": {
+ "name": "application",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "dsn": {
+ "name": "dsn",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "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": {
+ "application_dsn_unique": {
+ "name": "application_dsn_unique",
+ "columns": [
+ "dsn"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "application_workspace_id_workspace_id_fk": {
+ "name": "application_workspace_id_workspace_id_fk",
+ "tableFrom": "application",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "maintenance": {
+ "name": "maintenance",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "from": {
+ "name": "from",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "to": {
+ "name": "to",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "page_id": {
+ "name": "page_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": {
+ "maintenance_workspace_id_workspace_id_fk": {
+ "name": "maintenance_workspace_id_workspace_id_fk",
+ "tableFrom": "maintenance",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "maintenance_page_id_page_id_fk": {
+ "name": "maintenance_page_id_page_id_fk",
+ "tableFrom": "maintenance",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "maintenance_to_monitor": {
+ "name": "maintenance_to_monitor",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "maintenance_id": {
+ "name": "maintenance_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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "maintenance_to_monitor_monitor_id_monitor_id_fk": {
+ "name": "maintenance_to_monitor_monitor_id_monitor_id_fk",
+ "tableFrom": "maintenance_to_monitor",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "maintenance_to_monitor_maintenance_id_maintenance_id_fk": {
+ "name": "maintenance_to_monitor_maintenance_id_maintenance_id_fk",
+ "tableFrom": "maintenance_to_monitor",
+ "tableTo": "maintenance",
+ "columnsFrom": [
+ "maintenance_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "maintenance_to_monitor_monitor_id_maintenance_id_pk": {
+ "columns": [
+ "maintenance_id",
+ "monitor_id"
+ ],
+ "name": "maintenance_to_monitor_monitor_id_maintenance_id_pk"
+ }
+ },
+ "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 510424447..08e6edede 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -218,6 +218,13 @@
"when": 1716364430118,
"tag": "0030_elite_barracuda",
"breakpoints": true
+ },
+ {
+ "idx": 31,
+ "version": "6",
+ "when": 1717837961923,
+ "tag": "0031_lowly_gabe_jones",
+ "breakpoints": true
}
]
-}
+}
\ No newline at end of file
diff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.ts
index 31f6884f5..42801bff2 100644
--- a/packages/db/src/schema/index.ts
+++ b/packages/db/src/schema/index.ts
@@ -12,3 +12,4 @@ export * from "./invitations";
export * from "./incidents";
export * from "./monitor_tags";
export * from "./applications";
+export * from "./maintenances";
diff --git a/packages/db/src/schema/maintenances/index.ts b/packages/db/src/schema/maintenances/index.ts
new file mode 100644
index 000000000..2aa7ad78c
--- /dev/null
+++ b/packages/db/src/schema/maintenances/index.ts
@@ -0,0 +1,2 @@
+export * from "./maintenance";
+export * from "./validation";
diff --git a/packages/db/src/schema/maintenances/maintenance.ts b/packages/db/src/schema/maintenances/maintenance.ts
new file mode 100644
index 000000000..9ae79a9f8
--- /dev/null
+++ b/packages/db/src/schema/maintenances/maintenance.ts
@@ -0,0 +1,70 @@
+import { relations, sql } from "drizzle-orm";
+import {
+ integer,
+ primaryKey,
+ sqliteTable,
+ text,
+} from "drizzle-orm/sqlite-core";
+
+import { page } from "../pages";
+import { workspace } from "../workspaces";
+import { monitor } from "../monitors";
+
+export const maintenance = sqliteTable("maintenance", {
+ id: integer("id").primaryKey(),
+ title: text("title", { length: 256 }).notNull(),
+ message: text("message").notNull(),
+
+ from: integer("from", { mode: "timestamp" }).notNull(),
+ to: integer("to", { mode: "timestamp" }).notNull(),
+
+ workspaceId: integer("workspace_id").references(() => workspace.id),
+ pageId: integer("page_id").references(() => page.id),
+
+ createdAt: integer("created_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`
+ ),
+ updatedAt: integer("updated_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`
+ ),
+});
+
+export const maintenanceRelations = relations(maintenance, ({ one, many }) => ({
+ maintenancesToMonitors: many(maintenancesToMonitors),
+ workspace: one(workspace, {
+ fields: [maintenance.workspaceId],
+ references: [workspace.id],
+ }),
+}));
+
+export const maintenancesToMonitors = sqliteTable(
+ "maintenance_to_monitor",
+ {
+ monitorId: integer("monitor_id")
+ .notNull()
+ .references(() => monitor.id, { onDelete: "cascade" }),
+ maintenanceId: integer("maintenance_id")
+ .notNull()
+ .references(() => maintenance.id, { onDelete: "cascade" }),
+ createdAt: integer("created_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`
+ ),
+ },
+ (t) => ({
+ pk: primaryKey(t.monitorId, t.maintenanceId),
+ })
+);
+
+export const maintenancesToMonitorsRelations = relations(
+ maintenancesToMonitors,
+ ({ one }) => ({
+ monitor: one(monitor, {
+ fields: [maintenancesToMonitors.monitorId],
+ references: [monitor.id],
+ }),
+ page: one(maintenance, {
+ fields: [maintenancesToMonitors.maintenanceId],
+ references: [maintenance.id],
+ }),
+ })
+);
diff --git a/packages/db/src/schema/maintenances/validation.ts b/packages/db/src/schema/maintenances/validation.ts
new file mode 100644
index 000000000..8906d2967
--- /dev/null
+++ b/packages/db/src/schema/maintenances/validation.ts
@@ -0,0 +1,24 @@
+import { createInsertSchema, createSelectSchema } from "drizzle-zod";
+import { maintenance } from "./maintenance";
+import { z } from "zod";
+
+export const insertMaintenanceSchema = createInsertSchema(maintenance)
+ .extend({
+ // REMINDER: trick to make the react-hook-form controlled but not allow empty string
+ title: z.string().min(1, { message: "Required" }),
+ message: z.string().min(1, { message: "Required" }),
+
+ monitors: z.number().array().default([]).optional(),
+ })
+ // REMINDER: validate that `from` date is before `to` date
+ .refine((data) => data.from < data.to, {
+ path: ["to"],
+ message: "End date cannot be earlier than start date.",
+ });
+
+export const selectMaintenanceSchema = createSelectSchema(maintenance).extend({
+ monitors: z.number().array().default([]).optional(),
+});
+
+export type InsertMaintenance = z.infer<typeof insertMaintenanceSchema>;
+export type Maintenance = z.infer<typeof selectMaintenanceSchema>;
diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.ts
index 8914bca38..6200a90d3 100644
--- a/packages/db/src/schema/shared.ts
+++ b/packages/db/src/schema/shared.ts
@@ -8,6 +8,10 @@ import {
selectStatusReportUpdateSchema,
} from "./status_reports";
import { workspacePlanSchema } from "./workspaces";
+import {
+ maintenancesToMonitors,
+ selectMaintenanceSchema,
+} from "./maintenances";
// TODO: create a 'public-status' schema with all the different types and validations
@@ -25,10 +29,23 @@ export const selectStatusReportPageSchema = selectStatusReportSchema.extend({
monitorId: z.number(),
statusReportId: z.number(),
monitor: selectPublicMonitorSchema,
- }),
+ })
+ )
+ .default([]),
+});
+
+export const selectMaintenancePageSchema = selectMaintenanceSchema.extend({
+ maintenancesToMonitors: z
+ .array(
+ z.object({
+ monitorId: z.number(),
+ maintenanceId: z.number(),
+ })
)
.default([]),
});
+// TODO: it would be nice to automatically add the monitor relation here
+// .refine((data) => ({ monitors: data.maintenancesToMonitors.map((m) => m.monitorId) }));
export const selectPageSchemaWithRelation = selectPageSchema.extend({
monitors: z.array(selectMonitorSchema),
@@ -42,7 +59,7 @@ export const selectPageSchemaWithMonitorsRelation = selectPageSchema.extend({
pageId: z.number(),
order: z.number().default(0).optional(),
monitor: selectMonitorSchema,
- }),
+ })
),
});
@@ -51,6 +68,7 @@ export const selectPublicPageSchemaWithRelation = selectPageSchema
monitors: z.array(selectPublicMonitorSchema),
statusReports: z.array(selectStatusReportPageSchema),
incidents: z.array(selectIncidentSchema),
+ maintenances: z.array(selectMaintenancePageSchema),
workspacePlan: workspacePlanSchema
.nullable()
.default("free")
@@ -69,7 +87,7 @@ export const selectPublicStatusReportSchemaWithRelation =
monitorId: z.number(),
statusReportId: z.number(),
monitor: selectPublicMonitorSchema,
- }),
+ })
)
.default([]),
statusReportUpdates: z.array(selectStatusReportUpdateSchema),
diff --git a/packages/plans/src/config.ts b/packages/plans/src/config.ts
index ea914e74a..6c3432cac 100644
--- a/packages/plans/src/config.ts
+++ b/packages/plans/src/config.ts
@@ -22,6 +22,7 @@ export const allPlans: Record<
"multi-region": true,
"data-retention": "14 days",
"status-pages": 1,
+ maintenance: true,
"status-subscribers": false,
"custom-domain": false,
"password-protection": false,
@@ -43,6 +44,7 @@ export const allPlans: Record<
"multi-region": true,
"data-retention": "3 months",
"status-pages": 1,
+ maintenance: true,
"status-subscribers": true,
"custom-domain": true,
"password-protection": true,
@@ -64,6 +66,7 @@ export const allPlans: Record<
"multi-region": true,
"data-retention": "12 months",
"status-pages": 5,
+ maintenance: true,
"status-subscribers": true,
"custom-domain": true,
"password-protection": true,
@@ -85,6 +88,7 @@ export const allPlans: Record<
"multi-region": true,
"data-retention": "24 months",
"status-pages": 20,
+ maintenance: true,
"status-subscribers": true,
"custom-domain": true,
"password-protection": true,
diff --git a/packages/plans/src/pricing-table.ts b/packages/plans/src/pricing-table.ts
index 03cdf8fbb..c199de918 100644
--- a/packages/plans/src/pricing-table.ts
+++ b/packages/plans/src/pricing-table.ts
@@ -32,6 +32,10 @@ export const pricingTableConfig: Record<
value: "status-pages",
label: "Number of status pages",
},
+ {
+ value: "maintenance",
+ label: "Maintenance status",
+ },
{
value: "status-subscribers",
label: "Subscribers",
diff --git a/packages/plans/src/types.ts b/packages/plans/src/types.ts
index 599277def..233aeb0eb 100644
--- a/packages/plans/src/types.ts
+++ b/packages/plans/src/types.ts
@@ -8,6 +8,7 @@ export type Limits = {
"data-retention": string;
// status pages
"status-pages": number;
+ maintenance: boolean;
"status-subscribers": boolean;
"custom-domain": boolean;
"password-protection": boolean;
diff --git a/packages/react/src/utils.ts b/packages/react/src/utils.ts
index 612e34522..227f34041 100644
--- a/packages/react/src/utils.ts
+++ b/packages/react/src/utils.ts
@@ -30,6 +30,6 @@ export const statusDictionary: Record<
},
under_maintenance: {
label: "Under Maintenance",
- color: "bg-gray-500",
+ color: "bg-blue-500",
},
} as const;
diff --git a/packages/tracker/src/config.ts b/packages/tracker/src/config.ts
index 175098405..2b3f8685a 100644
--- a/packages/tracker/src/config.ts
+++ b/packages/tracker/src/config.ts
@@ -25,7 +25,7 @@ export const statusDetails: Record<Status, StatusDetails> = {
[Status.UnderMaintenance]: {
long: "Under Maintenance",
short: "Maintenance",
- variant: "empty",
+ variant: "maintenance",
},
[Status.Unknown]: {
long: "Unknown",
@@ -46,4 +46,5 @@ export const classNames: Record<StatusVariant, string> = {
down: "bg-red-500/90 data-[state=open]:bg-red-500 border-red-500",
empty: "bg-muted-foreground/20 data-[state=open]:bg-muted-foreground/30",
incident: "bg-red-500/90 data-[state=open]:bg-red-500 border-red-500",
+ maintenance: "bg-blue-500/90 data-[state=open]:bg-blue-500 border-blue-500",
};
diff --git a/packages/tracker/src/tracker.ts b/packages/tracker/src/tracker.ts
index 7eb325380..82b26b432 100644
--- a/packages/tracker/src/tracker.ts
+++ b/packages/tracker/src/tracker.ts
@@ -1,5 +1,6 @@
import type {
Incident,
+ Maintenance,
StatusReport,
StatusReportUpdate,
} from "@openstatus/db/src/schema";
@@ -16,6 +17,7 @@ type StatusReports = (StatusReport & {
statusReportUpdates?: StatusReportUpdate[];
})[];
type Incidents = Incident[];
+type Maintenances = Maintenance[];
/**
* Tracker Class is supposed to handle the data and calculate from a single monitor.
@@ -27,15 +29,18 @@ export class Tracker {
private data: Monitors = [];
private statusReports: StatusReports = [];
private incidents: Incidents = [];
+ private maintenances: Maintenances = [];
constructor(arg: {
data?: Monitors;
statusReports?: StatusReports;
incidents?: Incidents;
+ maintenances?: Maintenance[];
}) {
this.data = arg.data || []; // TODO: use another Class to handle a single Day
this.statusReports = arg.statusReports || [];
this.incidents = arg.incidents || [];
+ this.maintenances = arg.maintenances || [];
}
private calculateUptime(data: { ok: number; count: number }[]) {
@@ -51,7 +56,7 @@ export class Tracker {
prev.count += curr.count;
return prev;
},
- { count: 0, ok: 0 },
+ { count: 0, ok: 0 }
);
}
@@ -75,15 +80,26 @@ export class Tracker {
private isOngoingReport() {
const resolved: StatusReport["status"][] = ["monitoring", "resolved"];
return this.statusReports.some(
- (report) => !resolved.includes(report.status),
+ (report) => !resolved.includes(report.status)
);
}
+ private isOngoingMaintenance() {
+ return this.maintenances.some((maintenance) => {
+ const now = new Date();
+ return (
+ new Date(maintenance.from).getTime() <= now.getTime() &&
+ new Date(maintenance.to).getTime() >= now.getTime()
+ );
+ });
+ }
+
get totalUptime(): number {
return this.calculateUptime(this.data);
}
get currentStatus(): Status {
+ if (this.isOngoingMaintenance()) return Status.UnderMaintenance;
if (this.isOngoingReport()) return Status.DegradedPerformance;
if (this.isOngoingIncident()) return Status.Incident;
return this.calculateUptimeStatus(this.data);
@@ -136,7 +152,7 @@ export class Tracker {
private getStatusReportsByDay(props: Monitor): StatusReports {
const statusReports = this.statusReports?.filter((report) => {
const firstStatusReportUpdate = report?.statusReportUpdates?.sort(
- (a, b) => a.date.getTime() - b.date.getTime(),
+ (a, b) => a.date.getTime() - b.date.getTime()
)?.[0];
if (!firstStatusReportUpdate) return false;
@@ -147,6 +163,18 @@ export class Tracker {
return statusReports;
}
+ private getMaintenancesByDay(day: Date): Maintenances {
+ const maintenances = this.maintenances.filter((maintenance) => {
+ const eod = endOfDay(day);
+ const sod = startOfDay(day);
+ return (
+ maintenance.from.getTime() <= eod.getTime() &&
+ maintenance.to.getTime() >= sod.getTime()
+ );
+ });
+ return maintenances;
+ }
+
// TODO: it would be great to create a class to handle a single day
// FIXME: will be always generated on each tracker.days call - needs to be in the constructor?
get days() {
@@ -155,15 +183,18 @@ export class Tracker {
const blacklist = isInBlacklist(day);
const incidents = this.getIncidentsByDay(day);
const statusReports = this.getStatusReportsByDay(props);
+ const maintenances = this.getMaintenancesByDay(day);
const isMissingData = props.count === 0;
// FIXME:
- const status = incidents.length
+ const status = maintenances.length
+ ? Status.UnderMaintenance
+ : incidents.length
? Status.Incident
: isMissingData
- ? Status.Unknown
- : this.calculateUptimeStatus([props]);
+ ? Status.Unknown
+ : this.calculateUptimeStatus([props]);
const variant = statusDetails[status].variant;
const label = statusDetails[status].short;
@@ -173,6 +204,7 @@ export class Tracker {
blacklist,
incidents,
statusReports,
+ maintenances,
status,
variant,
label: isMissingData ? "Missing" : label,
diff --git a/packages/tracker/src/types.ts b/packages/tracker/src/types.ts
index 87060d450..a8980efcc 100644
--- a/packages/tracker/src/types.ts
+++ b/packages/tracker/src/types.ts
@@ -6,12 +6,19 @@ export enum Status {
DegradedPerformance = "degraded_performance",
PartialOutage = "partial_outage",
MajorOutage = "major_outage",
- UnderMaintenance = "under_maintenance", // not used
+ UnderMaintenance = "under_maintenance",
Unknown = "unknown",
Incident = "incident",
}
-export type StatusVariant = "up" | "degraded" | "down" | "empty" | "incident";
+// TODO: duplicate to `Status` enum above
+export type StatusVariant =
+ | "up"
+ | "degraded"
+ | "down"
+ | "empty"
+ | "incident"
+ | "maintenance";
export type StatusDetails = {
long: string;