Skip to content

Open-source status page, incident response and uptime monitoring

feat: status page unsubscription (#1736)

Maximilian Kaske25c3cd68a3e4
diff --git a/apps/dashboard/src/app/(dashboard)/status-pages/[id]/subscribers/page.tsx b/apps/dashboard/src/app/(dashboard)/status-pages/[id]/subscribers/page.tsx
index e3e5633f7..46376a025 100644
--- a/apps/dashboard/src/app/(dashboard)/status-pages/[id]/subscribers/page.tsx
+++ b/apps/dashboard/src/app/(dashboard)/status-pages/[id]/subscribers/page.tsx
@@ -39,6 +39,7 @@ const EXAMPLES = [
token: null,
acceptedAt: new Date(),
expiresAt: new Date(),
+ unsubscribedAt: null,
},
{
id: 2,
@@ -49,6 +50,7 @@ const EXAMPLES = [
token: null,
acceptedAt: new Date(),
expiresAt: new Date(),
+ unsubscribedAt: null,
},
];
diff --git a/apps/dashboard/src/components/data-table/subscribers/columns.tsx b/apps/dashboard/src/components/data-table/subscribers/columns.tsx
index c9d09fdcf..f0a138fdd 100644
--- a/apps/dashboard/src/components/data-table/subscribers/columns.tsx
+++ b/apps/dashboard/src/components/data-table/subscribers/columns.tsx
@@ -1,5 +1,6 @@
"use client";
+import { Badge } from "@/components/ui/badge";
import { formatDate } from "@/lib/formatter";
import type { RouterOutputs } from "@openstatus/api";
import type { ColumnDef } from "@tanstack/react-table";
@@ -14,6 +15,26 @@ export const columns: ColumnDef<Subscriber>[] = [
enableSorting: false,
enableHiding: false,
},
+ {
+ id: "status",
+ header: "Status",
+ enableSorting: false,
+ enableHiding: false,
+ cell: ({ row }) => {
+ const unsubscribedAt = row.original.unsubscribedAt;
+ const acceptedAt = row.original.acceptedAt;
+
+ if (unsubscribedAt) {
+ return <Badge variant="destructive">Unsubscribed</Badge>;
+ }
+
+ if (!acceptedAt) {
+ return <Badge variant="outline">Pending</Badge>;
+ }
+
+ return <Badge variant="secondary">Active</Badge>;
+ },
+ },
{
accessorKey: "createdAt",
header: "Created At",
@@ -44,6 +65,21 @@ export const columns: ColumnDef<Subscriber>[] = [
cellClassName: "font-mono",
},
},
+ {
+ accessorKey: "unsubscribedAt",
+ header: "Unsubscribed At",
+ enableSorting: false,
+ enableHiding: false,
+ cell: ({ row }) => {
+ const value = row.getValue("unsubscribedAt");
+ if (value instanceof Date) return formatDate(value);
+ if (!value) return "-";
+ return value;
+ },
+ meta: {
+ cellClassName: "font-mono",
+ },
+ },
{
id: "actions",
cell: ({ row }) => <DataTableRowActions row={row} />,
diff --git a/apps/server/src/routes/public/index.ts b/apps/server/src/routes/public/index.ts
index 36d4f2c29..3eb2bb41e 100644
--- a/apps/server/src/routes/public/index.ts
+++ b/apps/server/src/routes/public/index.ts
@@ -3,9 +3,11 @@ import { cors } from "hono/cors";
import { timing } from "hono/timing";
import { status } from "./status";
+import { unsubscribe } from "./unsubscribe";
export const publicRoute = new Hono();
publicRoute.use("*", cors());
publicRoute.use("*", timing());
publicRoute.route("/status", status);
+publicRoute.route("/unsubscribe", unsubscribe);
diff --git a/apps/server/src/routes/public/unsubscribe.ts b/apps/server/src/routes/public/unsubscribe.ts
new file mode 100644
index 000000000..82943206f
--- /dev/null
+++ b/apps/server/src/routes/public/unsubscribe.ts
@@ -0,0 +1,62 @@
+import { Hono } from "hono";
+
+import { db, eq } from "@openstatus/db";
+import { pageSubscriber } from "@openstatus/db/src/schema";
+
+/**
+ * RFC 8058 One-Click Unsubscribe Endpoint
+ *
+ * This endpoint handles POST requests from email clients that support one-click unsubscribe.
+ * Email clients send a POST request with form-urlencoded body containing "List-Unsubscribe=One-Click".
+ *
+ * @see https://datatracker.ietf.org/doc/html/rfc8058
+ */
+export const unsubscribe = new Hono();
+
+unsubscribe.post("/:token", async (c) => {
+ try {
+ const { token } = c.req.param();
+
+ // Validate token is a valid UUID format
+ const uuidRegex =
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+ if (!uuidRegex.test(token)) {
+ return c.json({ error: "Invalid token format" }, 400);
+ }
+
+ // Find the subscriber by token
+ const subscriber = await db
+ .select()
+ .from(pageSubscriber)
+ .where(eq(pageSubscriber.token, token))
+ .get();
+
+ // Return 404 if subscriber not found
+ if (!subscriber) {
+ return c.json({ error: "Subscriber not found" }, 404);
+ }
+
+ // Check if subscriber has verified their subscription
+ if (!subscriber.acceptedAt) {
+ return c.json({ error: "Subscription not verified" }, 400);
+ }
+
+ // Check if already unsubscribed
+ if (subscriber.unsubscribedAt) {
+ // Return 200 OK even if already unsubscribed (idempotent)
+ return c.json({ message: "Already unsubscribed" }, 200);
+ }
+
+ // Set unsubscribedAt timestamp
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.id, subscriber.id));
+
+ // Return 200 OK on success
+ return c.json({ message: "Successfully unsubscribed" }, 200);
+ } catch (e) {
+ console.error(`Error in one-click unsubscribe: ${e}`);
+ return c.json({ error: "Internal server error" }, 500);
+ }
+});
diff --git a/apps/server/src/routes/v1/maintenances/post.ts b/apps/server/src/routes/v1/maintenances/post.ts
index e4787ac5d..f7d3b22d3 100644
--- a/apps/server/src/routes/v1/maintenances/post.ts
+++ b/apps/server/src/routes/v1/maintenances/post.ts
@@ -141,10 +141,21 @@ export function registerPostMaintenance(api: typeof maintenancesApi) {
},
});
- if (_page && subscribers.length > 0) {
+ const validSubscribers = subscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (_page && validSubscribers.length > 0) {
await emailClient.sendStatusReportUpdate({
- to: subscribers.map((subscriber) => subscriber.email),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: _page.title,
+ pageSlug: _page.slug,
+ customDomain: _page.customDomain,
reportTitle: _maintenance.title,
status: "maintenance",
message: _maintenance.message,
diff --git a/apps/server/src/routes/v1/statusReportUpdates/post.ts b/apps/server/src/routes/v1/statusReportUpdates/post.ts
index cea5418e9..9323a9299 100644
--- a/apps/server/src/routes/v1/statusReportUpdates/post.ts
+++ b/apps/server/src/routes/v1/statusReportUpdates/post.ts
@@ -1,6 +1,6 @@
import { createRoute } from "@hono/zod-openapi";
-import { and, db, eq, isNotNull } from "@openstatus/db";
+import { and, db, eq, isNotNull, isNull } from "@openstatus/db";
import {
page,
pageSubscriber,
@@ -99,6 +99,7 @@ export function registerPostStatusReportUpdate(
and(
eq(pageSubscriber.pageId, _statusReport.pageId),
isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
),
)
.all();
@@ -114,10 +115,21 @@ export function registerPostStatusReportUpdate(
},
});
- if (_page && subscribers.length > 0) {
+ const validSubscribers = subscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (_page && validSubscribers.length > 0) {
await emailClient.sendStatusReportUpdate({
- to: subscribers.map((subscriber) => subscriber.email),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: _page.title,
+ pageSlug: _page.slug,
+ customDomain: _page.customDomain,
reportTitle: _statusReport.title,
status: _statusReportUpdate.status,
message: _statusReportUpdate.message,
diff --git a/apps/server/src/routes/v1/statusReports/post.ts b/apps/server/src/routes/v1/statusReports/post.ts
index 0a402b978..b80837724 100644
--- a/apps/server/src/routes/v1/statusReports/post.ts
+++ b/apps/server/src/routes/v1/statusReports/post.ts
@@ -143,6 +143,7 @@ export function registerPostStatusReport(api: typeof statusReportsApi) {
and(
eq(pageSubscriber.pageId, _newStatusReport.pageId),
isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
),
)
.all();
@@ -174,10 +175,21 @@ export function registerPostStatusReport(api: typeof statusReportsApi) {
});
}
- if (pageInfo && subscribers.length > 0) {
+ const validSubscribers = subscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (pageInfo && validSubscribers.length > 0) {
await emailClient.sendStatusReportUpdate({
- to: subscribers.map((subscriber) => subscriber.email),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: pageInfo.title,
+ pageSlug: pageInfo.slug,
+ customDomain: pageInfo.customDomain,
reportTitle: _newStatusReport.title,
status: _newStatusReportUpdate.status,
message: _newStatusReportUpdate.message,
diff --git a/apps/server/src/routes/v1/statusReports/subscriber-filtering.integration.test.ts b/apps/server/src/routes/v1/statusReports/subscriber-filtering.integration.test.ts
new file mode 100644
index 000000000..98d065d63
--- /dev/null
+++ b/apps/server/src/routes/v1/statusReports/subscriber-filtering.integration.test.ts
@@ -0,0 +1,275 @@
+import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+import { and, db, eq, isNotNull, isNull } from "@openstatus/db";
+import { page, pageSubscriber } from "@openstatus/db/src/schema";
+
+/**
+ * Integration tests for subscriber filtering in status report email queries.
+ * These tests verify that unsubscribed users are excluded from email notifications.
+ */
+
+let testPageId: number;
+const testWorkspaceId = 1; // Use existing test workspace from seed data
+
+beforeAll(async () => {
+ // Clean up any existing test data
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db.delete(page).where(eq(page.slug, "test-filtering-page"));
+
+ // Create a test page
+ const testPage = await db
+ .insert(page)
+ .values({
+ workspaceId: testWorkspaceId,
+ title: "Test Filtering Page",
+ description: "A test page for subscriber filtering tests",
+ slug: "test-filtering-page",
+ customDomain: "",
+ })
+ .returning()
+ .get();
+
+ testPageId = testPage.id;
+
+ // Create test subscribers with different states
+ // 1. Active subscriber (verified, not unsubscribed)
+ await db.insert(pageSubscriber).values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: null,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ });
+
+ // 2. Unsubscribed subscriber (verified, then unsubscribed)
+ await db.insert(pageSubscriber).values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ });
+
+ // 3. Pending subscriber (not verified)
+ await db.insert(pageSubscriber).values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: null,
+ unsubscribedAt: null,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ });
+});
+
+afterAll(async () => {
+ // Clean up test data
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db.delete(page).where(eq(page.slug, "test-filtering-page"));
+});
+
+describe("Subscriber filtering for email notifications", () => {
+ test("should exclude unsubscribed users from email queries", async () => {
+ // This query mirrors the exact query used in statusReports/post.ts and statusReportUpdates/post.ts
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ // Should only include active subscriber, not unsubscribed or pending
+ expect(subscribers.length).toBe(1);
+ expect(subscribers[0].email).toBe("[email protected]");
+ });
+
+ test("should exclude pending (unverified) users from email queries", async () => {
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ const pendingEmails = subscribers.filter(
+ (s) => s.email === "[email protected]",
+ );
+ expect(pendingEmails.length).toBe(0);
+ });
+
+ test("should not include unsubscribed user even if acceptedAt is set", async () => {
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ const unsubscribedEmails = subscribers.filter(
+ (s) => s.email === "[email protected]",
+ );
+ expect(unsubscribedEmails.length).toBe(0);
+ });
+
+ test("should return all subscribers without unsubscribedAt filter", async () => {
+ // Query without the unsubscribedAt filter - should include unsubscribed users
+ const allVerifiedSubscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ ),
+ )
+ .all();
+
+ // Should include both active and unsubscribed (both have acceptedAt set)
+ expect(allVerifiedSubscribers.length).toBe(2);
+
+ const emails = allVerifiedSubscribers.map((s) => s.email);
+ expect(emails).toContain("[email protected]");
+ expect(emails).toContain("[email protected]");
+ });
+
+ test("should correctly filter subscribers with valid tokens", async () => {
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ // Filter for valid tokens (non-null)
+ const validSubscribers = subscribers.filter(
+ (s): s is typeof s & { token: string } => s.token !== null,
+ );
+
+ expect(validSubscribers.length).toBe(1);
+ expect(validSubscribers[0].token).toBeDefined();
+ expect(validSubscribers[0].token).toMatch(
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
+ );
+ });
+});
+
+describe("Subscriber state transitions", () => {
+ test("should allow re-subscribing after unsubscription", async () => {
+ // Get the unsubscribed subscriber
+ const unsubscribedSub = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.email, "[email protected]"),
+ });
+
+ expect(unsubscribedSub?.unsubscribedAt).not.toBeNull();
+
+ // Simulate re-subscription by clearing unsubscribedAt
+ await db
+ .update(pageSubscriber)
+ .set({
+ unsubscribedAt: null,
+ acceptedAt: null, // Reset for re-verification
+ token: crypto.randomUUID(), // Generate new token
+ })
+ .where(eq(pageSubscriber.id, unsubscribedSub?.id));
+
+ // After re-subscription + verification, subscriber should be included
+ // (we need to set acceptedAt for verification)
+ await db
+ .update(pageSubscriber)
+ .set({ acceptedAt: new Date() })
+ .where(eq(pageSubscriber.id, unsubscribedSub?.id));
+
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ // Now should include both active and re-subscribed users
+ expect(subscribers.length).toBe(2);
+
+ // Restore original state for other tests
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.id, unsubscribedSub?.id));
+ });
+
+ test("should track unsubscription timestamp", async () => {
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.email, "[email protected]"),
+ });
+
+ expect(subscriber?.unsubscribedAt).toBeInstanceOf(Date);
+ });
+});
+
+describe("Query performance considerations", () => {
+ test("should use proper index-friendly query conditions", async () => {
+ // This test verifies the query uses conditions that can leverage indexes
+ // The conditions: pageId = X AND acceptedAt IS NOT NULL AND unsubscribedAt IS NULL
+ // can all be optimized with appropriate indexes
+
+ const startTime = performance.now();
+
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ const endTime = performance.now();
+
+ // Query should complete quickly (under 100ms for small datasets)
+ expect(endTime - startTime).toBeLessThan(100);
+ expect(subscribers).toBeDefined();
+ });
+});
diff --git a/apps/server/src/routes/v1/statusReports/update/post.ts b/apps/server/src/routes/v1/statusReports/update/post.ts
index 7c7813f76..97c0455ba 100644
--- a/apps/server/src/routes/v1/statusReports/update/post.ts
+++ b/apps/server/src/routes/v1/statusReports/update/post.ts
@@ -110,10 +110,21 @@ export function registerStatusReportUpdateRoutes(api: typeof statusReportsApi) {
)
.all();
- if (_statusReportWithRelations?.page) {
+ const validSubscribers = subscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (_statusReportWithRelations?.page && validSubscribers.length > 0) {
await emailClient.sendStatusReportUpdate({
- to: subscribers.map((subscriber) => subscriber.email),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: _statusReportWithRelations.page.title,
+ pageSlug: _statusReportWithRelations.page.slug,
+ customDomain: _statusReportWithRelations.page.customDomain,
reportTitle: _statusReportWithRelations.title,
status: _statusReportUpdate.status,
message: _statusReportUpdate.message,
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/layout.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/layout.tsx
new file mode 100644
index 000000000..9edb11c2d
--- /dev/null
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/layout.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import {
+ Status,
+ StatusContent,
+ StatusDescription,
+ StatusHeader,
+ StatusTitle,
+} from "@/components/status-page/status";
+import { useTRPC } from "@/lib/trpc/client";
+import { useQuery } from "@tanstack/react-query";
+import { useParams } from "next/navigation";
+
+export default function UnsubscribeLayout({
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ const { domain } = useParams<{ domain: string }>();
+ const trpc = useTRPC();
+ const { data: page } = useQuery(
+ trpc.statusPage.get.queryOptions({ slug: domain }),
+ );
+
+ if (!page) return null;
+
+ return (
+ <Status>
+ <StatusHeader>
+ <StatusTitle>{page.title}</StatusTitle>
+ <StatusDescription>{page.description}</StatusDescription>
+ </StatusHeader>
+ <StatusContent>{children}</StatusContent>
+ </Status>
+ );
+}
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/page.tsx
new file mode 100644
index 000000000..a7a854940
--- /dev/null
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/unsubscribe/[token]/page.tsx
@@ -0,0 +1,123 @@
+"use client";
+
+import {
+ StatusBlankContainer,
+ StatusBlankContent,
+ StatusBlankDescription,
+ StatusBlankLink,
+ StatusBlankTitle,
+} from "@/components/status-page/status-blank";
+import { Button } from "@/components/ui/button";
+import { useTRPC } from "@/lib/trpc/client";
+import { useMutation, useQuery } from "@tanstack/react-query";
+import { useParams } from "next/navigation";
+
+export default function UnsubscribePage() {
+ const trpc = useTRPC();
+ const { token, domain } = useParams<{ token: string; domain: string }>();
+
+ const subscriberQuery = useQuery(
+ trpc.statusPage.getSubscriberByToken.queryOptions({ token, domain }),
+ );
+
+ const unsubscribeMutation = useMutation(
+ trpc.statusPage.unsubscribe.mutationOptions({}),
+ );
+
+ const handleUnsubscribe = () => {
+ unsubscribeMutation.mutate({ token, domain });
+ };
+
+ // Loading state
+ if (subscriberQuery.isLoading) {
+ return (
+ <StatusBlankContainer>
+ <StatusBlankContent>
+ <StatusBlankTitle>Loading...</StatusBlankTitle>
+ </StatusBlankContent>
+ </StatusBlankContainer>
+ );
+ }
+
+ // Invalid/expired token or already unsubscribed
+ if (!subscriberQuery.data) {
+ return (
+ <StatusBlankContainer>
+ <StatusBlankContent>
+ <StatusBlankTitle className="text-destructive">
+ Invalid or expired link
+ </StatusBlankTitle>
+ <StatusBlankDescription>
+ This unsubscribe link is no longer valid. You may have already
+ unsubscribed.
+ </StatusBlankDescription>
+ <StatusBlankLink href="../">Go back</StatusBlankLink>
+ </StatusBlankContent>
+ </StatusBlankContainer>
+ );
+ }
+
+ // Success state after unsubscribing
+ if (unsubscribeMutation.isSuccess) {
+ return (
+ <StatusBlankContainer>
+ <StatusBlankContent>
+ <StatusBlankTitle className="text-success">
+ Successfully unsubscribed
+ </StatusBlankTitle>
+ <StatusBlankDescription>
+ You will no longer receive email notifications from{" "}
+ {subscriberQuery.data.pageName}.
+ </StatusBlankDescription>
+ <StatusBlankLink href="../">Go back</StatusBlankLink>
+ </StatusBlankContent>
+ </StatusBlankContainer>
+ );
+ }
+
+ // Error state
+ if (unsubscribeMutation.isError) {
+ return (
+ <StatusBlankContainer>
+ <StatusBlankContent>
+ <StatusBlankTitle className="text-destructive">
+ {unsubscribeMutation.error?.message || "Something went wrong"}
+ </StatusBlankTitle>
+ <StatusBlankDescription>
+ Please try again or contact support if the issue persists.
+ </StatusBlankDescription>
+ <StatusBlankLink href="../">Go back</StatusBlankLink>
+ </StatusBlankContent>
+ </StatusBlankContainer>
+ );
+ }
+
+ // Confirmation state (initial view)
+ return (
+ <StatusBlankContainer>
+ <StatusBlankContent>
+ <StatusBlankTitle>Unsubscribe from notifications</StatusBlankTitle>
+ <StatusBlankDescription>
+ You are about to unsubscribe{" "}
+ <span className="font-semibold">
+ {subscriberQuery.data.maskedEmail}
+ </span>{" "}
+ from{" "}
+ <span className="font-semibold">{subscriberQuery.data.pageName}</span>{" "}
+ status updates.
+ </StatusBlankDescription>
+ <div className="flex justify-center gap-2">
+ <StatusBlankLink href="../">Cancel</StatusBlankLink>
+ <Button
+ variant="destructive"
+ size="sm"
+ onClick={handleUnsubscribe}
+ disabled={unsubscribeMutation.isPending}
+ >
+ {unsubscribeMutation.isPending ? "Unsubscribing..." : "Unsubscribe"}
+ </Button>
+ </div>
+ </StatusBlankContent>
+ </StatusBlankContainer>
+ );
+}
diff --git a/packages/api/src/router/email/index.ts b/packages/api/src/router/email/index.ts
index 4d90c4b02..4d6038f66 100644
--- a/packages/api/src/router/email/index.ts
+++ b/packages/api/src/router/email/index.ts
@@ -61,14 +61,23 @@ export const emailRouter = createTRPCRouter({
opts.ctx.workspace.id
)
return;
- if (!_statusReportUpdate.statusReport.page.pageSubscribers.length)
- return;
+ const validSubscribers =
+ _statusReportUpdate.statusReport.page.pageSubscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (!validSubscribers.length) return;
await emailClient.sendStatusReportUpdate({
- to: _statusReportUpdate.statusReport.page.pageSubscribers.map(
- (subscriber) => subscriber.email,
- ),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: _statusReportUpdate.statusReport.page.title,
+ pageSlug: _statusReportUpdate.statusReport.page.slug,
+ customDomain: _statusReportUpdate.statusReport.page.customDomain,
reportTitle: _statusReportUpdate.statusReport.title,
status: _statusReportUpdate.status,
message: _statusReportUpdate.message,
@@ -109,13 +118,22 @@ export const emailRouter = createTRPCRouter({
if (!_maintenance) return;
if (!_maintenance.page) return;
- if (!_maintenance.page.pageSubscribers.length) return;
+ const validSubscribers = _maintenance.page.pageSubscribers.filter(
+ (s): s is typeof s & { token: string } =>
+ s.token !== null &&
+ s.acceptedAt !== null &&
+ s.unsubscribedAt === null,
+ );
+ if (!validSubscribers.length) return;
await emailClient.sendStatusReportUpdate({
- to: _maintenance.page.pageSubscribers.map(
- (subscriber) => subscriber.email,
- ),
+ subscribers: validSubscribers.map((subscriber) => ({
+ email: subscriber.email,
+ token: subscriber.token,
+ })),
pageTitle: _maintenance.page.title,
+ pageSlug: _maintenance.page.slug,
+ customDomain: _maintenance.page.customDomain,
reportTitle: _maintenance.title,
status: "maintenance",
message: _maintenance.message,
diff --git a/packages/api/src/router/statusPage.e2e.test.ts b/packages/api/src/router/statusPage.e2e.test.ts
new file mode 100644
index 000000000..54647f87a
--- /dev/null
+++ b/packages/api/src/router/statusPage.e2e.test.ts
@@ -0,0 +1,722 @@
+import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+import { and, db, eq, isNotNull, isNull } from "@openstatus/db";
+import { page, pageSubscriber, workspace } from "@openstatus/db/src/schema";
+
+/**
+ * End-to-end integration tests for the full unsubscribe flow.
+ * These tests simulate the complete user journey:
+ * subscribe -> verify -> receive email -> unsubscribe
+ */
+
+let testPageId: number;
+let testWorkspaceId: number;
+const testSlug = "e2e-unsubscribe-test-page";
+const testEmail = "[email protected]";
+let subscriberToken: string;
+
+beforeAll(async () => {
+ // Clean up any existing test data
+ await db.delete(pageSubscriber).where(eq(pageSubscriber.email, testEmail));
+ await db.delete(page).where(eq(page.slug, testSlug));
+
+ // Get an existing workspace (use workspace id 1 from seed data)
+ const existingWorkspace = await db.query.workspace.findFirst({
+ where: eq(workspace.id, 1),
+ });
+
+ if (!existingWorkspace) {
+ throw new Error(
+ "Test workspace not found. Please ensure seed data exists.",
+ );
+ }
+
+ testWorkspaceId = existingWorkspace.id;
+
+ // Create a test page
+ const testPage = await db
+ .insert(page)
+ .values({
+ workspaceId: testWorkspaceId,
+ title: "E2E Test Status Page",
+ description: "A test page for E2E unsubscribe flow tests",
+ slug: testSlug,
+ customDomain: "",
+ })
+ .returning()
+ .get();
+
+ testPageId = testPage.id;
+});
+
+afterAll(async () => {
+ // Clean up test data
+ await db.delete(pageSubscriber).where(eq(pageSubscriber.email, testEmail));
+ await db.delete(page).where(eq(page.slug, testSlug));
+});
+
+describe("Full unsubscribe flow: subscribe -> verify -> unsubscribe", () => {
+ test("Step 1: User subscribes to status page", async () => {
+ // Simulate subscription by inserting a subscriber
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: testEmail,
+ token: crypto.randomUUID(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7), // 7 days
+ })
+ .returning()
+ .get();
+
+ expect(subscriber.id).toBeDefined();
+ expect(subscriber.email).toBe(testEmail);
+ expect(subscriber.token).toBeDefined();
+ expect(subscriber.acceptedAt).toBeNull();
+ expect(subscriber.unsubscribedAt).toBeNull();
+
+ if (!subscriber.token) {
+ throw new Error("Subscriber token is undefined");
+ }
+
+ subscriberToken = subscriber.token;
+ });
+
+ test("Step 2: User verifies their email subscription", async () => {
+ // Verify the subscription
+ await db
+ .update(pageSubscriber)
+ .set({ acceptedAt: new Date() })
+ .where(eq(pageSubscriber.token, subscriberToken));
+
+ // Verify the subscription is now active
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, subscriberToken),
+ });
+
+ expect(subscriber?.acceptedAt).not.toBeNull();
+ expect(subscriber?.unsubscribedAt).toBeNull();
+ });
+
+ test("Step 3: Verified subscriber is included in email recipient list", async () => {
+ // This query mirrors the exact query used in statusReports/post.ts
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ expect(subscribers.length).toBe(1);
+ expect(subscribers[0].email).toBe(testEmail);
+ expect(subscribers[0].token).toBe(subscriberToken);
+ });
+
+ test("Step 4: User clicks unsubscribe and sets unsubscribedAt", async () => {
+ // Simulate the unsubscribe action
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.token, subscriberToken));
+
+ // Verify the unsubscription
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, subscriberToken),
+ });
+
+ expect(subscriber?.unsubscribedAt).not.toBeNull();
+ expect(subscriber?.unsubscribedAt).toBeInstanceOf(Date);
+ });
+
+ test("Step 5: Unsubscribed user is excluded from email recipient list", async () => {
+ // This query mirrors the exact query used in statusReports/post.ts
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ expect(subscribers.length).toBe(0);
+ });
+});
+
+describe("Confirmation page displays correct information", () => {
+ let confirmPageToken: string;
+
+ beforeAll(async () => {
+ // Create a fresh subscriber for confirmation page tests
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(), // Already verified
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!subscriber.token) {
+ throw new Error("Subscriber token is undefined");
+ }
+
+ confirmPageToken = subscriber.token;
+ });
+
+ afterAll(async () => {
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ });
+
+ test("Confirmation page displays correct page name", async () => {
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, confirmPageToken),
+ with: {
+ page: true,
+ },
+ });
+
+ expect(subscriber?.page.title).toBe("E2E Test Status Page");
+ });
+
+ test("Confirmation page displays masked email (first char + *** + @domain)", async () => {
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, confirmPageToken),
+ });
+
+ if (!subscriber) {
+ throw new Error("Subscriber not found");
+ }
+
+ const email = subscriber.email;
+ expect(email).toBe("[email protected]");
+
+ // Apply the same masking logic as in the API
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("c***@example.com");
+ });
+
+ test("Email masking works for single character local part", async () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("a***@example.com");
+ });
+
+ test("Email masking works for long local part", async () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("v***@example.com");
+ });
+});
+
+describe("Clicking confirm sets unsubscribedAt timestamp", () => {
+ let unsubscribeToken: string;
+
+ beforeAll(async () => {
+ // Create a fresh subscriber
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(), // Already verified
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!subscriber.token) {
+ throw new Error("Subscriber token is undefined");
+ }
+
+ unsubscribeToken = subscriber.token;
+ });
+
+ afterAll(async () => {
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ });
+
+ test("Before clicking confirm, unsubscribedAt is null", async () => {
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, unsubscribeToken),
+ });
+
+ expect(subscriber?.unsubscribedAt).toBeNull();
+ });
+
+ test("After clicking confirm, unsubscribedAt is set to current timestamp", async () => {
+ const beforeUnsubscribe = new Date();
+
+ // Simulate clicking "Confirm Unsubscribe"
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.token, unsubscribeToken));
+
+ const afterUnsubscribe = new Date();
+
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, unsubscribeToken),
+ });
+
+ if (!subscriber) {
+ throw new Error("Subscriber not found");
+ }
+
+ expect(subscriber.unsubscribedAt).not.toBeNull();
+ expect(subscriber.unsubscribedAt).toBeInstanceOf(Date);
+
+ // Verify the timestamp is within the expected range
+ if (!subscriber.unsubscribedAt) {
+ throw new Error("Subscriber unsubscribedAt is undefined");
+ }
+
+ // SQLite stores timestamps in seconds, so we compare at second precision
+ const unsubscribedTime = Math.floor(
+ subscriber.unsubscribedAt.getTime() / 1000,
+ );
+ const beforeTime = Math.floor(beforeUnsubscribe.getTime() / 1000);
+ const afterTime = Math.floor(afterUnsubscribe.getTime() / 1000);
+
+ expect(unsubscribedTime).toBeGreaterThanOrEqual(beforeTime);
+ expect(unsubscribedTime).toBeLessThanOrEqual(afterTime);
+ });
+
+ test("Subscriber state transitions correctly through the flow", async () => {
+ // Verify the subscriber has completed the full lifecycle
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, unsubscribeToken),
+ });
+
+ // Has been verified (acceptedAt is set)
+ expect(subscriber?.acceptedAt).not.toBeNull();
+
+ // Has been unsubscribed (unsubscribedAt is set)
+ expect(subscriber?.unsubscribedAt).not.toBeNull();
+
+ // Token is still present (for audit purposes)
+ expect(subscriber?.token).toBe(unsubscribeToken);
+ });
+});
+
+describe("Unsubscribed user does not receive new emails", () => {
+ let _activeToken: string;
+ let unsubscribedToken: string;
+ let pendingToken: string;
+
+ beforeAll(async () => {
+ // Clean up and create multiple subscribers with different states
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+
+ // Active subscriber
+ const active = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: null,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!active.token) {
+ throw new Error("Active subscriber token is undefined");
+ }
+
+ _activeToken = active.token;
+
+ // Unsubscribed subscriber
+ const unsubscribed = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!unsubscribed.token) {
+ throw new Error("Unsubscribed subscriber token is undefined");
+ }
+
+ unsubscribedToken = unsubscribed.token;
+
+ // Pending (unverified) subscriber
+ const pending = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: null,
+ unsubscribedAt: null,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!pending.token) {
+ throw new Error("Pending subscriber token is undefined");
+ }
+
+ pendingToken = pending.token;
+ });
+
+ afterAll(async () => {
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ });
+
+ test("Email query returns only active subscribers with valid tokens", async () => {
+ // This mirrors the exact query pattern used in email-sending routes
+ const emailRecipients = await db
+ .select({
+ email: pageSubscriber.email,
+ token: pageSubscriber.token,
+ })
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ // Should only include active subscriber
+ expect(emailRecipients.length).toBeGreaterThanOrEqual(1);
+
+ const emails = emailRecipients.map((r) => r.email);
+ expect(emails).toContain("[email protected]");
+ expect(emails).not.toContain("[email protected]");
+ expect(emails).not.toContain("[email protected]");
+ });
+
+ test("Unsubscribed users are filtered out even with acceptedAt set", async () => {
+ // Verify the unsubscribed user has acceptedAt set
+ const unsubscribedUser = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, unsubscribedToken),
+ });
+
+ expect(unsubscribedUser?.acceptedAt).not.toBeNull();
+ expect(unsubscribedUser?.unsubscribedAt).not.toBeNull();
+
+ // Query with proper filters
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ const foundUnsubscribed = subscribers.find(
+ (s) => s.email === "[email protected]",
+ );
+ expect(foundUnsubscribed).toBeUndefined();
+ });
+
+ test("Pending users are filtered out (not verified)", async () => {
+ // Verify the pending user has no acceptedAt
+ const pendingUser = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, pendingToken),
+ });
+
+ expect(pendingUser?.acceptedAt).toBeNull();
+
+ // Query with proper filters
+ const subscribers = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ const foundPending = subscribers.find(
+ (s) => s.email === "[email protected]",
+ );
+ expect(foundPending).toBeUndefined();
+ });
+
+ test("Email recipients list includes token for unsubscribe URL generation", async () => {
+ const emailRecipients = await db
+ .select({
+ email: pageSubscriber.email,
+ token: pageSubscriber.token,
+ })
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ // Filter for valid tokens (as done in email sending routes)
+ const validRecipients = emailRecipients.filter(
+ (r): r is { email: string; token: string } => r.token !== null,
+ );
+
+ expect(validRecipients.length).toBeGreaterThanOrEqual(1);
+
+ // Each valid recipient should have a UUID token
+ for (const recipient of validRecipients) {
+ expect(recipient.token).toMatch(
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
+ );
+ }
+ });
+});
+
+describe("Re-subscription after unsubscribe flow", () => {
+ let resubscribeToken: string;
+
+ beforeAll(async () => {
+ // Clean up
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+
+ // Create an initially subscribed and verified user
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: null,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!subscriber.token) {
+ throw new Error("Subscriber token is undefined");
+ }
+
+ resubscribeToken = subscriber.token;
+ });
+
+ afterAll(async () => {
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ });
+
+ test("User can complete full subscribe -> unsubscribe -> resubscribe cycle", async () => {
+ // Step 1: Verify initial subscription state
+ let subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.email, "[email protected]"),
+ });
+
+ expect(subscriber?.acceptedAt).not.toBeNull();
+ expect(subscriber?.unsubscribedAt).toBeNull();
+
+ // Step 2: User unsubscribes
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.id, subscriber?.id));
+
+ subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.id, subscriber?.id),
+ });
+
+ expect(subscriber?.unsubscribedAt).not.toBeNull();
+
+ // Step 3: User is excluded from emails
+ const subscribersAfterUnsub = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ eq(pageSubscriber.email, "[email protected]"),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ expect(subscribersAfterUnsub.length).toBe(0);
+
+ // Step 4: User re-subscribes (simulating the re-subscription flow)
+ const newToken = crypto.randomUUID();
+ await db
+ .update(pageSubscriber)
+ .set({
+ unsubscribedAt: null,
+ acceptedAt: null, // Requires re-verification
+ token: newToken,
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .where(eq(pageSubscriber.id, subscriber?.id));
+
+ // Step 5: User is still excluded (not yet verified)
+ const subscribersPendingVerify = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ eq(pageSubscriber.email, "[email protected]"),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ expect(subscribersPendingVerify.length).toBe(0);
+
+ // Step 6: User verifies their email again
+ await db
+ .update(pageSubscriber)
+ .set({ acceptedAt: new Date() })
+ .where(eq(pageSubscriber.token, newToken));
+
+ // Step 7: User is now included in email list again
+ const subscribersAfterReverify = await db
+ .select()
+ .from(pageSubscriber)
+ .where(
+ and(
+ eq(pageSubscriber.pageId, testPageId),
+ eq(pageSubscriber.email, "[email protected]"),
+ isNotNull(pageSubscriber.acceptedAt),
+ isNull(pageSubscriber.unsubscribedAt),
+ ),
+ )
+ .all();
+
+ expect(subscribersAfterReverify.length).toBe(1);
+ expect(subscribersAfterReverify[0].token).toBe(newToken);
+ expect(subscribersAfterReverify[0].token).not.toBe(resubscribeToken);
+ });
+});
+
+describe("Invalid token handling", () => {
+ test("Non-existent token returns no subscriber", async () => {
+ const fakeToken = crypto.randomUUID();
+
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, fakeToken),
+ });
+
+ expect(subscriber).toBeUndefined();
+ });
+
+ test("Invalid UUID format is handled gracefully", async () => {
+ const invalidToken = "not-a-valid-uuid";
+
+ // The database query will still work, just return no results
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, invalidToken),
+ });
+
+ expect(subscriber).toBeUndefined();
+ });
+
+ test("Already unsubscribed token returns subscriber with unsubscribedAt set", async () => {
+ // Create an unsubscribed subscriber
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: crypto.randomUUID(),
+ acceptedAt: new Date(),
+ unsubscribedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ if (!subscriber.token) {
+ throw new Error("Subscriber token is undefined");
+ }
+
+ // Query the subscriber
+ const found = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, subscriber.token),
+ });
+
+ expect(found).toBeDefined();
+ expect(found?.unsubscribedAt).not.toBeNull();
+
+ // Clean up
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ });
+});
diff --git a/packages/api/src/router/statusPage.ts b/packages/api/src/router/statusPage.ts
index 5a62f0349..4ec67567d 100644
--- a/packages/api/src/router/statusPage.ts
+++ b/packages/api/src/router/statusPage.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
-import { and, eq, inArray, isNotNull, sql } from "@openstatus/db";
+import { and, eq, inArray, sql } from "@openstatus/db";
import {
maintenance,
monitorsToPages,
@@ -873,22 +873,59 @@ export const statusPageRouter = createTRPCRouter({
});
}
- const _alreadySubscribed =
+ // Check for existing subscriber (active or unsubscribed)
+ const _existingSubscriber =
await opts.ctx.db.query.pageSubscriber.findFirst({
where: and(
eq(pageSubscriber.pageId, _page.id),
eq(pageSubscriber.email, opts.input.email),
- isNotNull(pageSubscriber.acceptedAt),
),
});
- if (_alreadySubscribed) {
+ // If already subscribed and verified (not unsubscribed), reject
+ if (
+ _existingSubscriber?.acceptedAt &&
+ !_existingSubscriber.unsubscribedAt
+ ) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Email already subscribed",
});
}
+ // Handle re-subscription: clear unsubscribedAt, regenerate token, reset acceptedAt
+ if (_existingSubscriber?.unsubscribedAt) {
+ const updatedSubscriber = await opts.ctx.db
+ .update(pageSubscriber)
+ .set({
+ unsubscribedAt: null,
+ acceptedAt: null,
+ token: crypto.randomUUID(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .where(eq(pageSubscriber.id, _existingSubscriber.id))
+ .returning()
+ .get();
+
+ return updatedSubscriber.id;
+ }
+
+ // Handle pending re-subscription (not yet verified): regenerate token
+ if (_existingSubscriber && !_existingSubscriber.acceptedAt) {
+ const updatedSubscriber = await opts.ctx.db
+ .update(pageSubscriber)
+ .set({
+ token: crypto.randomUUID(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .where(eq(pageSubscriber.id, _existingSubscriber.id))
+ .returning()
+ .get();
+
+ return updatedSubscriber.id;
+ }
+
+ // New subscription
const _pageSubscriber = await opts.ctx.db
.insert(pageSubscriber)
.values({
@@ -1020,4 +1057,96 @@ export const statusPageRouter = createTRPCRouter({
return true;
}),
+
+ getSubscriberByToken: publicProcedure
+ .input(
+ z.object({ token: z.string().uuid(), domain: z.string().toLowerCase() }),
+ )
+ .query(async (opts) => {
+ const _page = await opts.ctx.db.query.page.findFirst({
+ where: sql`lower(${page.slug}) = ${opts.input.domain} OR lower(${page.customDomain}) = ${opts.input.domain}`,
+ });
+
+ if (!_page) return null;
+
+ const _pageSubscriber = await opts.ctx.db.query.pageSubscriber.findFirst({
+ where: and(
+ eq(pageSubscriber.token, opts.input.token),
+ eq(pageSubscriber.pageId, _page.id),
+ ),
+ });
+
+ // Return null if not found or already unsubscribed
+ if (!_pageSubscriber) {
+ return null;
+ }
+
+ if (_pageSubscriber.unsubscribedAt) {
+ return null;
+ }
+
+ // Mask email: show first character, then ***, then @domain
+ const email = _pageSubscriber.email;
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ return {
+ pageName: _page.title,
+ maskedEmail,
+ };
+ }),
+
+ unsubscribe: publicProcedure
+ .input(
+ z.object({ token: z.string().uuid(), domain: z.string().toLowerCase() }),
+ )
+ .mutation(async (opts) => {
+ const _page = await opts.ctx.db.query.page.findFirst({
+ where: sql`lower(${page.slug}) = ${opts.input.domain} OR lower(${page.customDomain}) = ${opts.input.domain}`,
+ });
+
+ if (!_page) return null;
+
+ const _pageSubscriber = await opts.ctx.db.query.pageSubscriber.findFirst({
+ where: and(
+ eq(pageSubscriber.token, opts.input.token),
+ eq(pageSubscriber.pageId, _page.id),
+ ),
+ });
+
+ if (!_pageSubscriber) {
+ throw new TRPCError({
+ code: "NOT_FOUND",
+ message: "Subscription not found",
+ });
+ }
+
+ if (!_pageSubscriber.acceptedAt) {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "Subscription not yet verified",
+ });
+ }
+
+ if (_pageSubscriber.unsubscribedAt) {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "Already unsubscribed",
+ });
+ }
+
+ await opts.ctx.db
+ .update(pageSubscriber)
+ .set({
+ unsubscribedAt: new Date(),
+ })
+ .where(eq(pageSubscriber.id, _pageSubscriber.id))
+ .execute();
+
+ return {
+ success: true,
+ pageName: _page.title,
+ };
+ }),
});
diff --git a/packages/api/src/router/statusPage.unsubscribe.test.ts b/packages/api/src/router/statusPage.unsubscribe.test.ts
new file mode 100644
index 000000000..bf111bd07
--- /dev/null
+++ b/packages/api/src/router/statusPage.unsubscribe.test.ts
@@ -0,0 +1,298 @@
+import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+
+import { db, eq } from "@openstatus/db";
+import { page, pageSubscriber } from "@openstatus/db/src/schema";
+
+// Test data setup
+let testPageId: number;
+let _testSubscriberId: number;
+let testToken: string;
+const testWorkspaceId = 1; // Use existing test workspace from seed data
+
+beforeAll(async () => {
+ // Clean up any existing test data
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db.delete(page).where(eq(page.slug, "test-unsubscribe-page"));
+
+ // Create a test page
+ const testPage = await db
+ .insert(page)
+ .values({
+ workspaceId: testWorkspaceId,
+ title: "Test Unsubscribe Page",
+ description: "A test page for unsubscribe tests",
+ slug: "test-unsubscribe-page",
+ customDomain: "",
+ })
+ .returning()
+ .get();
+
+ testPageId = testPage.id;
+
+ // Create a verified subscriber for testing
+ testToken = crypto.randomUUID();
+ const subscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: testToken,
+ acceptedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ _testSubscriberId = subscriber.id;
+});
+
+afterAll(async () => {
+ // Clean up test data
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db
+ .delete(pageSubscriber)
+ .where(eq(pageSubscriber.email, "[email protected]"));
+ await db.delete(page).where(eq(page.slug, "test-unsubscribe-page"));
+});
+
+describe("getSubscriberByToken", () => {
+ test("should return subscriber info with masked email for valid token", async () => {
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, testToken),
+ with: { page: true },
+ });
+
+ expect(subscriber).toBeDefined();
+ expect(subscriber?.page.title).toBe("Test Unsubscribe Page");
+
+ // Manually mask the email to test the masking logic
+ const email = subscriber?.email;
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("t***@example.com");
+ });
+
+ test("should return null for non-existent token", async () => {
+ const nonExistentToken = crypto.randomUUID();
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, nonExistentToken),
+ });
+
+ expect(subscriber).toBeUndefined();
+ });
+
+ test("should return null for already unsubscribed user", async () => {
+ // Create an unsubscribed subscriber
+ const unsubscribedToken = crypto.randomUUID();
+ await db.insert(pageSubscriber).values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: unsubscribedToken,
+ acceptedAt: new Date(),
+ unsubscribedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ });
+
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, unsubscribedToken),
+ });
+
+ expect(subscriber).toBeDefined();
+ expect(subscriber?.unsubscribedAt).not.toBeNull();
+ });
+
+ test("should properly mask emails with single character local part", async () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("a***@example.com");
+ });
+
+ test("should properly mask emails with long local part", async () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("v***@example.com");
+ });
+});
+
+describe("unsubscribe mutation", () => {
+ test("should unsubscribe a verified subscriber successfully", async () => {
+ // Create a fresh subscriber for this test
+ const newToken = crypto.randomUUID();
+ const newSubscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: newToken,
+ acceptedAt: new Date(),
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ // Simulate unsubscribe operation
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.id, newSubscriber.id));
+
+ // Verify unsubscribed
+ const updatedSubscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.id, newSubscriber.id),
+ });
+
+ expect(updatedSubscriber?.unsubscribedAt).not.toBeNull();
+ expect(updatedSubscriber?.unsubscribedAt).toBeInstanceOf(Date);
+ });
+
+ test("should fail for non-existent token", async () => {
+ const nonExistentToken = crypto.randomUUID();
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.token, nonExistentToken),
+ });
+
+ expect(subscriber).toBeUndefined();
+ });
+
+ test("should fail for unverified subscriber", async () => {
+ // Create an unverified subscriber
+ const unverifiedToken = crypto.randomUUID();
+ const unverifiedSubscriber = await db
+ .insert(pageSubscriber)
+ .values({
+ pageId: testPageId,
+ email: "[email protected]",
+ token: unverifiedToken,
+ acceptedAt: null, // Not verified
+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
+ })
+ .returning()
+ .get();
+
+ expect(unverifiedSubscriber.acceptedAt).toBeNull();
+ });
+
+ test("should fail for already unsubscribed user", async () => {
+ // Get the unsubscribed subscriber from earlier test
+ const unsubscribedSubscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.email, "[email protected]"),
+ });
+
+ expect(unsubscribedSubscriber).toBeDefined();
+ expect(unsubscribedSubscriber?.unsubscribedAt).not.toBeNull();
+ });
+
+ test("should set unsubscribedAt to current timestamp", async () => {
+ const beforeUnsubscribe = new Date();
+
+ // Get subscriber and unsubscribe
+ const subscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.email, "[email protected]"),
+ });
+
+ if (subscriber) {
+ await db
+ .update(pageSubscriber)
+ .set({ unsubscribedAt: new Date() })
+ .where(eq(pageSubscriber.id, subscriber.id));
+
+ const updatedSubscriber = await db.query.pageSubscriber.findFirst({
+ where: eq(pageSubscriber.id, subscriber.id),
+ });
+
+ const afterUnsubscribe = new Date();
+
+ expect(updatedSubscriber?.unsubscribedAt).toBeDefined();
+ expect(
+ updatedSubscriber?.unsubscribedAt?.getTime(),
+ ).toBeGreaterThanOrEqual(beforeUnsubscribe.getTime() - 1000);
+ expect(updatedSubscriber?.unsubscribedAt?.getTime()).toBeLessThanOrEqual(
+ afterUnsubscribe.getTime() + 1000,
+ );
+ }
+ });
+});
+
+describe("email masking logic", () => {
+ test("should mask email j***@example.com correctly", () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("j***@example.com");
+ });
+
+ test("should handle empty local part gracefully", () => {
+ // Edge case: if somehow we have @domain only
+ const email = "@example.com";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("***@example.com");
+ });
+
+ test("should preserve domain in masked email", () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("u***@custom-domain.io");
+ });
+
+ test("should handle complex domain", () => {
+ const email = "[email protected]";
+ const [localPart, domain] = email.split("@");
+ const maskedEmail =
+ localPart.length > 0 ? `${localPart[0]}***@${domain}` : `***@${domain}`;
+
+ expect(maskedEmail).toBe("t***@subdomain.example.co.uk");
+ });
+});
+
+describe("token validation", () => {
+ test("should validate UUID format for token", () => {
+ const validToken = crypto.randomUUID();
+ const uuidRegex =
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+ expect(validToken).toMatch(uuidRegex);
+ });
+
+ test("should reject invalid UUID format", () => {
+ const invalidToken = "not-a-valid-uuid";
+ const uuidRegex =
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+ expect(invalidToken).not.toMatch(uuidRegex);
+ });
+});
diff --git a/packages/db/drizzle/0053_groovy_doctor_strange.sql b/packages/db/drizzle/0053_groovy_doctor_strange.sql
new file mode 100644
index 000000000..8a54a0ff0
--- /dev/null
+++ b/packages/db/drizzle/0053_groovy_doctor_strange.sql
@@ -0,0 +1 @@
+ALTER TABLE `page_subscriber` ADD `unsubscribed_at` integer;
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/0053_snapshot.json b/packages/db/drizzle/meta/0053_snapshot.json
new file mode 100644
index 000000000..b7a702ea2
--- /dev/null
+++ b/packages/db/drizzle/meta/0053_snapshot.json
@@ -0,0 +1,3078 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "cf9ebf5a-5a27-455a-8542-1441972faa63",
+ "prevId": "cc596587-5474-42a7-b638-1b7c771fbc5e",
+ "tables": {
+ "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
+ },
+ "limits": {
+ "name": "limits",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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
+ },
+ "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": {
+ "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"
+ },
+ "status_report_page_id_page_id_fk": {
+ "name": "status_report_page_id_page_id_fk",
+ "tableFrom": "status_report",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "status_report_update": {
+ "name": "status_report_update",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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
+ },
+ "force_theme": {
+ "name": "force_theme",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'system'"
+ },
+ "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
+ },
+ "access_type": {
+ "name": "access_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'public'"
+ },
+ "auth_email_domains": {
+ "name": "auth_email_domains",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "homepage_url": {
+ "name": "homepage_url",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "contact_url": {
+ "name": "contact_url",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "legacy_page": {
+ "name": "legacy_page",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "configuration": {
+ "name": "configuration",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "show_monitor_values": {
+ "name": "show_monitor_values",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": true
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": "'http'"
+ },
+ "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": "''"
+ },
+ "external_name": {
+ "name": "external_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "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
+ },
+ "timeout": {
+ "name": "timeout",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 45000
+ },
+ "degraded_after": {
+ "name": "degraded_after",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "assertions": {
+ "name": "assertions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "otel_endpoint": {
+ "name": "otel_endpoint",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "otel_headers": {
+ "name": "otel_headers",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "public": {
+ "name": "public",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "retry": {
+ "name": "retry",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 3
+ },
+ "follow_redirects": {
+ "name": "follow_redirects",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": true
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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
+ },
+ "monitor_group_id": {
+ "name": "monitor_group_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "group_order": {
+ "name": "group_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"
+ },
+ "monitors_to_pages_monitor_group_id_monitor_group_id_fk": {
+ "name": "monitors_to_pages_monitor_group_id_monitor_group_id_fk",
+ "tableFrom": "monitors_to_pages",
+ "tableTo": "monitor_group",
+ "columnsFrom": [
+ "monitor_group_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": {},
+ "checkConstraints": {}
+ },
+ "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
+ },
+ "unsubscribed_at": {
+ "name": "unsubscribed_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": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "notification_trigger": {
+ "name": "notification_trigger",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "notification_id": {
+ "name": "notification_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cron_timestamp": {
+ "name": "cron_timestamp",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "notification_id_monitor_id_crontimestampe": {
+ "name": "notification_id_monitor_id_crontimestampe",
+ "columns": [
+ "notification_id",
+ "monitor_id",
+ "cron_timestamp"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "notification_trigger_monitor_id_monitor_id_fk": {
+ "name": "notification_trigger_monitor_id_monitor_id_fk",
+ "tableFrom": "notification_trigger",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notification_trigger_notification_id_notification_id_fk": {
+ "name": "notification_trigger_notification_id_notification_id_fk",
+ "tableFrom": "notification_trigger",
+ "tableTo": "notification",
+ "columnsFrom": [
+ "notification_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": {},
+ "checkConstraints": {}
+ },
+ "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": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "maintenance_to_monitor": {
+ "name": "maintenance_to_monitor",
+ "columns": {
+ "maintenance_id": {
+ "name": "maintenance_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "monitor_id": {
+ "name": "monitor_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_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"
+ },
+ "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"
+ }
+ },
+ "compositePrimaryKeys": {
+ "maintenance_to_monitor_maintenance_id_monitor_id_pk": {
+ "columns": [
+ "maintenance_id",
+ "monitor_id"
+ ],
+ "name": "maintenance_to_monitor_maintenance_id_monitor_id_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "check": {
+ "name": "check",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "regions": {
+ "name": "regions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "url": {
+ "name": "url",
+ "type": "text(4096)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "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'"
+ },
+ "count_requests": {
+ "name": "count_requests",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 1
+ },
+ "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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "check_workspace_id_workspace_id_fk": {
+ "name": "check_workspace_id_workspace_id_fk",
+ "tableFrom": "check",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "monitor_run": {
+ "name": "monitor_run",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "runned_at": {
+ "name": "runned_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'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitor_run_workspace_id_workspace_id_fk": {
+ "name": "monitor_run_workspace_id_workspace_id_fk",
+ "tableFrom": "monitor_run",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "monitor_run_monitor_id_monitor_id_fk": {
+ "name": "monitor_run_monitor_id_monitor_id_fk",
+ "tableFrom": "monitor_run",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "private_location": {
+ "name": "private_location",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_seen_at": {
+ "name": "last_seen_at",
+ "type": "integer",
+ "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": {},
+ "foreignKeys": {
+ "private_location_workspace_id_workspace_id_fk": {
+ "name": "private_location_workspace_id_workspace_id_fk",
+ "tableFrom": "private_location",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "private_location_to_monitor": {
+ "name": "private_location_to_monitor",
+ "columns": {
+ "private_location_id": {
+ "name": "private_location_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "monitor_id": {
+ "name": "monitor_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'))"
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "private_location_to_monitor_private_location_id_private_location_id_fk": {
+ "name": "private_location_to_monitor_private_location_id_private_location_id_fk",
+ "tableFrom": "private_location_to_monitor",
+ "tableTo": "private_location",
+ "columnsFrom": [
+ "private_location_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "private_location_to_monitor_monitor_id_monitor_id_fk": {
+ "name": "private_location_to_monitor_monitor_id_monitor_id_fk",
+ "tableFrom": "private_location_to_monitor",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "monitor_group": {
+ "name": "monitor_group",
+ "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
+ },
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "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_group_workspace_id_workspace_id_fk": {
+ "name": "monitor_group_workspace_id_workspace_id_fk",
+ "tableFrom": "monitor_group",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "monitor_group_page_id_page_id_fk": {
+ "name": "monitor_group_page_id_page_id_fk",
+ "tableFrom": "monitor_group",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "viewer": {
+ "name": "viewer",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "emailVerified": {
+ "name": "emailVerified",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "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": {
+ "viewer_email_unique": {
+ "name": "viewer_email_unique",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "viewer_accounts": {
+ "name": "viewer_accounts",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "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
+ },
+ "providerAccountId": {
+ "name": "providerAccountId",
+ "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": {
+ "viewer_accounts_user_id_viewer_id_fk": {
+ "name": "viewer_accounts_user_id_viewer_id_fk",
+ "tableFrom": "viewer_accounts",
+ "tableTo": "viewer",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "viewer_accounts_provider_providerAccountId_pk": {
+ "columns": [
+ "provider",
+ "providerAccountId"
+ ],
+ "name": "viewer_accounts_provider_providerAccountId_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "viewer_session": {
+ "name": "viewer_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": {
+ "viewer_session_user_id_viewer_id_fk": {
+ "name": "viewer_session_user_id_viewer_id_fk",
+ "tableFrom": "viewer_session",
+ "tableTo": "viewer",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "api_key": {
+ "name": "api_key",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "hashed_token": {
+ "name": "hashed_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_by_id": {
+ "name": "created_by_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'))"
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "api_key_prefix_unique": {
+ "name": "api_key_prefix_unique",
+ "columns": [
+ "prefix"
+ ],
+ "isUnique": true
+ },
+ "api_key_hashed_token_unique": {
+ "name": "api_key_hashed_token_unique",
+ "columns": [
+ "hashed_token"
+ ],
+ "isUnique": true
+ },
+ "api_key_prefix_idx": {
+ "name": "api_key_prefix_idx",
+ "columns": [
+ "prefix"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "api_key_workspace_id_workspace_id_fk": {
+ "name": "api_key_workspace_id_workspace_id_fk",
+ "tableFrom": "api_key",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "api_key_created_by_id_user_id_fk": {
+ "name": "api_key_created_by_id_user_id_fk",
+ "tableFrom": "api_key",
+ "tableTo": "user",
+ "columnsFrom": [
+ "created_by_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json
index 684379f9c..5bef4dcc4 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -372,6 +372,13 @@
"when": 1767797078062,
"tag": "0052_illegal_killraven",
"breakpoints": true
+ },
+ {
+ "idx": 53,
+ "version": "6",
+ "when": 1736935200000,
+ "tag": "0053_groovy_doctor_strange",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/packages/db/src/schema/page_subscribers/page_subscribers.ts b/packages/db/src/schema/page_subscribers/page_subscribers.ts
index 7eff6dc1d..d6c8ff2a8 100644
--- a/packages/db/src/schema/page_subscribers/page_subscribers.ts
+++ b/packages/db/src/schema/page_subscribers/page_subscribers.ts
@@ -14,6 +14,7 @@ export const pageSubscriber = sqliteTable("page_subscriber", {
token: text("token"),
acceptedAt: integer("accepted_at", { mode: "timestamp" }),
expiresAt: integer("expires_at", { mode: "timestamp" }),
+ unsubscribedAt: integer("unsubscribed_at", { mode: "timestamp" }),
createdAt: integer("created_at", { mode: "timestamp" }).default(
sql`(strftime('%s', 'now'))`,
),
diff --git a/packages/emails/emails/status-report.tsx b/packages/emails/emails/status-report.tsx
index fdc7a6866..8a82e04e9 100644
--- a/packages/emails/emails/status-report.tsx
+++ b/packages/emails/emails/status-report.tsx
@@ -6,9 +6,11 @@ import {
Head,
Heading,
Html,
+ Link,
Markdown,
Preview,
Row,
+ Section,
Text,
} from "@react-email/components";
import { z } from "zod";
@@ -29,6 +31,7 @@ export const StatusReportSchema = z.object({
message: z.string(),
reportTitle: z.string(),
monitors: z.array(z.string()),
+ unsubscribeUrl: z.string().url().optional(),
});
export type StatusReportProps = z.infer<typeof StatusReportSchema>;
@@ -57,6 +60,7 @@ function StatusReportEmail({
reportTitle,
pageTitle,
monitors,
+ unsubscribeUrl,
}: StatusReportProps) {
return (
<Html>
@@ -110,14 +114,25 @@ function StatusReportEmail({
<Markdown>{message}</Markdown>
</Column>
</Row>
+ {unsubscribeUrl && (
+ <Section style={{ marginTop: "24px", textAlign: "center" }}>
+ <Text style={{ fontSize: "12px", color: "#6b7280" }}>
+ <Link
+ href={unsubscribeUrl}
+ style={{ color: "#6b7280", textDecoration: "underline" }}
+ >
+ Unsubscribe
+ </Link>{" "}
+ from these notifications.
+ </Text>
+ </Section>
+ )}
</Layout>
</Body>
</Html>
);
}
-// TODO: add unsubscribe link!
-
StatusReportEmail.PreviewProps = {
pageTitle: "OpenStatus Status",
reportTitle: "API Unavaible",
@@ -132,7 +147,7 @@ StatusReportEmail.PreviewProps = {
---
-### What’s Changed
+### What's Changed
- All queued workflows are now being picked up and completed successfully.
- Jobs are running normally on our GitHub App. ### Current Issue: Cache Action Unavailable Attempts to re-publish our action to GitHub Marketplace are returning 500 Internal Server Errors. This prevents the updated versions from going live.
@@ -143,9 +158,11 @@ StatusReportEmail.PreviewProps = {
### Next Update
-We’ll post another update by **19:00 UTC** today or sooner if critical developments occur. We apologize for the inconvenience and appreciate your patience as we restore full cache functionality.
+We'll post another update by **19:00 UTC** today or sooner if critical developments occur. We apologize for the inconvenience and appreciate your patience as we restore full cache functionality.
`,
monitors: ["OpenStatus API", "OpenStatus Webhook"],
+ unsubscribeUrl:
+ "https://status.openstatus.dev/unsubscribe/550e8400-e29b-41d4-a716-446655440000",
};
export default StatusReportEmail;
diff --git a/packages/emails/src/client.integration.test.tsx b/packages/emails/src/client.integration.test.tsx
new file mode 100644
index 000000000..3e5517ee9
--- /dev/null
+++ b/packages/emails/src/client.integration.test.tsx
@@ -0,0 +1,128 @@
+/** @jsxImportSource react */
+
+import { describe, expect, test } from "bun:test";
+import { render } from "@react-email/render";
+import StatusReportEmail from "../emails/status-report";
+
+describe("Status Report Email - Unsubscribe Link in Body", () => {
+ const unsubscribeUrl =
+ "https://openstatus.openstatus.dev/unsubscribe/test-token";
+
+ test("should include unsubscribe link in email body when URL is provided", async () => {
+ const html = await render(
+ <StatusReportEmail
+ pageTitle="Test Page"
+ reportTitle="Test Report"
+ status="investigating"
+ date={new Date().toISOString()}
+ message="Test message"
+ monitors={["Monitor 1"]}
+ unsubscribeUrl={unsubscribeUrl}
+ />,
+ );
+
+ expect(html).toContain(unsubscribeUrl);
+ expect(html).toContain("Unsubscribe");
+ });
+
+ test("should not include unsubscribe section when URL is not provided", async () => {
+ const html = await render(
+ <StatusReportEmail
+ pageTitle="Test Page"
+ reportTitle="Test Report"
+ status="investigating"
+ date={new Date().toISOString()}
+ message="Test message"
+ monitors={["Monitor 1"]}
+ />,
+ );
+
+ // Should not contain the unsubscribe text when no URL provided
+ expect(html).not.toContain("from these notifications");
+ });
+
+ test("should render unsubscribe link as clickable", async () => {
+ const html = await render(
+ <StatusReportEmail
+ pageTitle="Test Page"
+ reportTitle="Test Report"
+ status="investigating"
+ date={new Date().toISOString()}
+ message="Test message"
+ monitors={["Monitor 1"]}
+ unsubscribeUrl={unsubscribeUrl}
+ />,
+ );
+
+ // Check that the URL is in an href attribute
+ expect(html).toContain(`href="${unsubscribeUrl}"`);
+ });
+
+ test("should display unsubscribe link with proper styling", async () => {
+ const html = await render(
+ <StatusReportEmail
+ pageTitle="Test Page"
+ reportTitle="Test Report"
+ status="investigating"
+ date={new Date().toISOString()}
+ message="Test message"
+ monitors={["Monitor 1"]}
+ unsubscribeUrl={unsubscribeUrl}
+ />,
+ );
+
+ // Check for muted styling (gray color for footer)
+ expect(html).toContain("#6b7280");
+ });
+});
+
+describe("Status Report Email - Email Content Validation", () => {
+ test("should include all required email fields", async () => {
+ const props = {
+ pageTitle: "OpenStatus",
+ reportTitle: "API Outage",
+ status: "investigating" as const,
+ date: "2024-01-15T10:00:00.000Z",
+ message: "We are investigating the issue",
+ monitors: ["API", "Web"],
+ unsubscribeUrl: "https://openstatus.openstatus.dev/unsubscribe/test",
+ };
+
+ const html = await render(<StatusReportEmail {...props} />);
+
+ expect(html).toContain(props.pageTitle);
+ expect(html).toContain(props.reportTitle);
+ expect(html).toContain(props.message);
+ expect(html).toContain("API");
+ expect(html).toContain("Web");
+ expect(html).toContain(props.unsubscribeUrl);
+ });
+
+ test("should handle all status types correctly", async () => {
+ const statuses = [
+ "investigating",
+ "identified",
+ "monitoring",
+ "resolved",
+ "maintenance",
+ ] as const;
+
+ for (const status of statuses) {
+ const html = await render(
+ <StatusReportEmail
+ pageTitle="Test"
+ reportTitle="Test Report"
+ status={status}
+ date={new Date().toISOString()}
+ message="Test"
+ monitors={[]}
+ unsubscribeUrl="https://example.com/unsubscribe"
+ />,
+ );
+
+ // Should render without errors and contain the status
+ // Note: status is rendered lowercase in HTML with text-transform: uppercase CSS
+ expect(html).toContain(status);
+ }
+ });
+});
diff --git a/packages/emails/src/client.tsx b/packages/emails/src/client.tsx
index 3bfbd0853..35f5504a8 100644
--- a/packages/emails/src/client.tsx
+++ b/packages/emails/src/client.tsx
@@ -90,32 +90,46 @@ export class EmailClient {
}
public async sendStatusReportUpdate(
- req: StatusReportProps & { to: string[] },
+ req: StatusReportProps & {
+ subscribers: Array<{ email: string; token: string }>;
+ pageSlug: string;
+ customDomain?: string | null;
+ },
) {
+ const statusPageBaseUrl = req.customDomain
+ ? `https://${req.customDomain}`
+ : `https://${req.pageSlug}.openstatus.dev`;
+
if (process.env.NODE_ENV === "development") {
console.log(
- `Sending status report update emails to ${req.to.join(", ")}`,
+ `Sending status report update emails to ${req.subscribers
+ .map((s) => s.email)
+ .join(", ")}`,
);
return;
}
- // const html = await render(<StatusReportEmail {...req} />);
-
- for (const recipients of chunk(req.to, 100)) {
+ for (const recipients of chunk(req.subscribers, 100)) {
const sendEmail = Effect.tryPromise({
try: () =>
this.client.batch.send(
- recipients.map((subscriber) => ({
- from: `${req.pageTitle} <[email protected]>`,
- subject: req.reportTitle,
- to: subscriber,
- // html,
- react: <StatusReportEmail {...req} />,
- })),
+ recipients.map((subscriber) => {
+ const unsubscribeUrl = `${statusPageBaseUrl}/unsubscribe/${subscriber.token}`;
+ return {
+ from: `${req.pageTitle} <[email protected]>`,
+ subject: req.reportTitle,
+ to: subscriber.email,
+ react: (
+ <StatusReportEmail {...req} unsubscribeUrl={unsubscribeUrl} />
+ ),
+ };
+ }),
),
catch: (_unknown) =>
new Error(
- `Error sending status report update batch to ${recipients}`,
+ `Error sending status report update batch to ${recipients.map(
+ (r) => r.email,
+ )}`,
),
}).pipe(
Effect.andThen((result) =>
@@ -130,7 +144,7 @@ export class EmailClient {
}
console.log(
- `Sent status report update email to ${req.to.length} subscribers`,
+ `Sent status report update email to ${req.subscribers.length} subscribers`,
);
}
diff --git a/ralph/.gitignore b/ralph/.gitignore
new file mode 100644
index 000000000..e93c46927
--- /dev/null
+++ b/ralph/.gitignore
@@ -0,0 +1,4 @@
+# Ignore PRD and progress files as they are specific to local development
+prd.json
+progress.txt
+
diff --git a/ralph/afk-ralph.sh b/ralph/afk-ralph.sh
old mode 100644
new mode 100755
diff --git a/ralph/prd.json b/ralph/prd.json
deleted file mode 100644
index e0f0b0c63..000000000
--- a/ralph/prd.json
+++ /dev/null
@@ -1,8 +0,0 @@
-[
- {
- "category": "functional",
- "description": "When a user is on wrong dashboard /status-pages/[id] redirect him to /status-pages",
- "steps": ["Redirect user no access for page id", "Avoid throwing an error"],
- "passes": false
- }
-]
diff --git a/ralph/progress.txt b/ralph/progress.txt
deleted file mode 100644
index 788ad5038..000000000
--- a/ralph/progress.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-## Completed Tasks
-
-### Task 1: Redirect user with no access for status-pages/[id]
-- **PRD Item**: "When a user is on wrong dashboard /status-pages/[id] redirect him to /status-pages"
-- **Status**: COMPLETED
-- **Commit**: b72b1bf5
-- **Changes Made**:
- - Modified `apps/dashboard/src/app/(dashboard)/status-pages/[id]/layout.tsx`
- - Changed from `prefetchQuery` to `fetchQuery` to properly check page access
- - Added try-catch block to handle errors when user doesn't have access to the page
- - Redirects to `/status-pages` instead of throwing an error when:
- - Page doesn't exist
- - User doesn't have access to the page (wrong workspace)