Skip to content

Open-source status page, incident response and uptime monitoring

feat: custom api key (#1715)

Thibault Le Ouaya40cde270909
diff --git a/apps/dashboard/src/app/(dashboard)/settings/general/layout.tsx b/apps/dashboard/src/app/(dashboard)/settings/general/layout.tsx
index 0c9a86dae..e841c2255 100644
--- a/apps/dashboard/src/app/(dashboard)/settings/general/layout.tsx
+++ b/apps/dashboard/src/app/(dashboard)/settings/general/layout.tsx
@@ -17,7 +17,7 @@ export default async function Layout({
const queryClient = getQueryClient();
await queryClient.prefetchQuery(trpc.member.list.queryOptions());
await queryClient.prefetchQuery(trpc.invitation.list.queryOptions());
- await queryClient.prefetchQuery(trpc.apiKey.get.queryOptions());
+ await queryClient.prefetchQuery(trpc.apiKeyRouter.getAll.queryOptions());
return (
<HydrateClient>
diff --git a/apps/dashboard/src/components/data-table/settings/api-key/data-table.tsx b/apps/dashboard/src/components/data-table/settings/api-key/data-table.tsx
index 46f4d3eb0..e3c01d80e 100644
--- a/apps/dashboard/src/components/data-table/settings/api-key/data-table.tsx
+++ b/apps/dashboard/src/components/data-table/settings/api-key/data-table.tsx
@@ -1,29 +1,77 @@
+import { QuickActions } from "@/components/dropdowns/quick-actions";
import {
Table,
TableBody,
TableCell,
TableHead,
+ TableHeader,
TableRow,
} from "@/components/ui/table";
+import { formatDate } from "@/lib/formatter";
+import { useTRPC } from "@/lib/trpc/client";
import type { RouterOutputs } from "@openstatus/api";
+import { useMutation } from "@tanstack/react-query";
-type ApiKey = RouterOutputs["apiKey"]["get"];
+type ApiKey = RouterOutputs["apiKeyRouter"]["getAll"][number];
+
+export function DataTable({
+ apiKeys,
+ refetch,
+}: {
+ apiKeys: ApiKey[];
+ refetch: () => void;
+}) {
+ const trpc = useTRPC();
+ const revokeApiKeyMutation = useMutation(
+ trpc.apiKeyRouter.revoke.mutationOptions({
+ onSuccess: () => refetch(),
+ }),
+ );
-export function DataTable({ apiKey }: { apiKey: ApiKey }) {
return (
- <Table>
- <TableBody>
- <TableRow className="[&>:not(:last-child)]:border-r">
- <TableHead className="h-auto bg-muted/50">Created At</TableHead>
- <TableCell>
- {new Date(apiKey.createdAt).toLocaleDateString()}
- </TableCell>
- </TableRow>
- <TableRow className="[&>:not(:last-child)]:border-r">
- <TableHead className="h-auto bg-muted/50">Token</TableHead>
- <TableCell>{apiKey.start}...</TableCell>
- </TableRow>
- </TableBody>
- </Table>
+ <div className="overflow-x-auto">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Name</TableHead>
+ <TableHead>Description</TableHead>
+ <TableHead>Prefix</TableHead>
+ <TableHead>Expires</TableHead>
+ <TableHead>
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {apiKeys.map((apiKey) => (
+ <TableRow key={apiKey.id}>
+ <TableCell className="font-medium">{apiKey.name}</TableCell>
+ <TableCell className="max-w-[200px] truncate text-muted-foreground">
+ {apiKey.description ?? "-"}
+ </TableCell>
+ <TableCell>
+ <code className="text-xs">{apiKey.prefix}...</code>
+ </TableCell>
+ <TableCell className="text-sm">
+ {apiKey.expiresAt ? formatDate(apiKey.expiresAt) : "-"}
+ </TableCell>
+ <TableCell>
+ <div className="flex justify-end">
+ <QuickActions
+ deleteAction={{
+ confirmationValue: apiKey.name ?? "api key",
+ submitAction: async () =>
+ await revokeApiKeyMutation.mutateAsync({
+ keyId: apiKey.id,
+ }),
+ }}
+ />
+ </div>
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </div>
);
}
diff --git a/apps/dashboard/src/components/forms/settings/form-api-key.tsx b/apps/dashboard/src/components/forms/settings/form-api-key.tsx
index 2cb09d619..90130e594 100644
--- a/apps/dashboard/src/components/forms/settings/form-api-key.tsx
+++ b/apps/dashboard/src/components/forms/settings/form-api-key.tsx
@@ -7,7 +7,6 @@ import {
} from "@/components/content/empty-state";
import { EmptyStateContainer } from "@/components/content/empty-state";
import { DataTable } from "@/components/data-table/settings/api-key/data-table";
-import { FormAlertDialog } from "@/components/forms/form-alert-dialog";
import {
FormCard,
FormCardContent,
@@ -26,52 +25,105 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
+import { Calendar } from "@/components/ui/calendar";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { Textarea } from "@/components/ui/textarea";
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard";
import { useTRPC } from "@/lib/trpc/client";
+import { cn } from "@/lib/utils";
+import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQuery } from "@tanstack/react-query";
import { isTRPCClientError } from "@trpc/client";
-import { Copy } from "lucide-react";
+import { format } from "date-fns";
+import { CalendarIcon, Check, Copy } from "lucide-react";
import { useState, useTransition } from "react";
+import { useForm } from "react-hook-form";
import { toast } from "sonner";
+import { z } from "zod";
// we should prefetch the api key on the server (layout)
+const schema = z.object({
+ name: z.string().min(1, "Name is required"),
+ description: z.string().optional(),
+ expiresAt: z.string().optional(),
+});
+
+type FormValues = z.infer<typeof schema>;
+
export function FormApiKey() {
const trpc = useTRPC();
const [isPending, startTransition] = useTransition();
- const { copy } = useCopyToClipboard();
+ const { copy, isCopied } = useCopyToClipboard();
const [result, setResult] = useState<{
- keyId: string;
+ token: string;
key: string;
} | null>(null);
+ const [createDialogOpen, setCreateDialogOpen] = useState(false);
+
+ const form = useForm<FormValues>({
+ resolver: zodResolver(schema),
+ defaultValues: {
+ name: "",
+ description: "",
+ expiresAt: "",
+ },
+ });
+
const { data: workspace } = useQuery(
trpc.workspace.getWorkspace.queryOptions(),
);
- const { data: apiKey, refetch } = useQuery(trpc.apiKey.get.queryOptions());
+ const { data: apiKeys = [], refetch } = useQuery(
+ trpc.apiKeyRouter.getAll.queryOptions(),
+ );
const createApiKeyMutation = useMutation(
- trpc.apiKey.create.mutationOptions({
+ trpc.apiKeyRouter.create.mutationOptions({
onSuccess: (data) => {
if (data) {
- setResult(data);
+ refetch();
+ setResult({ token: data.token, key: data.key.name });
+ setCreateDialogOpen(false);
+ form.reset();
} else {
throw new Error("Failed to create API key");
}
},
}),
);
- const revokeApiKeyMutation = useMutation(
- trpc.apiKey.revoke.mutationOptions({
- onSuccess: () => refetch(),
- }),
- );
- async function createAction() {
- if (isPending || !workspace) return;
+ function createAction(values: FormValues) {
+ if (isPending || !workspace) {
+ return;
+ }
startTransition(async () => {
try {
const promise = createApiKeyMutation.mutateAsync({
- ownerId: workspace.id,
+ name: values.name.trim(),
+ description: values.description?.trim() || undefined,
+ expiresAt: values.expiresAt ? new Date(values.expiresAt) : undefined,
});
toast.promise(promise, {
loading: "Creating...",
@@ -93,21 +145,21 @@ export function FormApiKey() {
return (
<FormCard>
<FormCardHeader>
- <FormCardTitle>API Key</FormCardTitle>
+ <FormCardTitle>API Keys</FormCardTitle>
<FormCardDescription>
- Create and revoke your API key.
+ Create and manage your API keys.
</FormCardDescription>
</FormCardHeader>
<FormCardContent>
- {!apiKey ? (
+ {apiKeys.length === 0 ? (
<EmptyStateContainer>
- <EmptyStateTitle>No API key</EmptyStateTitle>
+ <EmptyStateTitle>No API keys</EmptyStateTitle>
<EmptyStateDescription>
Access your data via API.
</EmptyStateDescription>
</EmptyStateContainer>
) : (
- <DataTable apiKey={apiKey} />
+ <DataTable apiKeys={apiKeys} refetch={refetch} />
)}
</FormCardContent>
<FormCardFooter>
@@ -122,52 +174,159 @@ export function FormApiKey() {
</Link>
.
</FormCardFooterInfo>
- {!apiKey ? (
- <Button size="sm" onClick={createAction}>
- Create
- </Button>
- ) : (
- <FormAlertDialog
- confirmationValue="API Key"
- submitAction={async () => {
- await revokeApiKeyMutation.mutateAsync({
- keyId: apiKey.keyId,
- });
- }}
- />
- )}
+ <Dialog open={createDialogOpen} onOpenChange={setCreateDialogOpen}>
+ <DialogTrigger asChild>
+ <Button size="sm">Create</Button>
+ </DialogTrigger>
+ <DialogContent>
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(createAction)}>
+ <DialogHeader>
+ <DialogTitle>Create API Key</DialogTitle>
+ <DialogDescription>
+ Create a new API key to access your workspace data.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="space-y-4">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Name</FormLabel>
+ <FormControl>
+ <Input placeholder="Production API" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder="Used for production deployment"
+ rows={3}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="expiresAt"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Expiration Date</FormLabel>
+ <Popover modal>
+ <FormControl>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ className={cn(
+ "w-[240px] pl-3 text-left font-normal",
+ !field.value && "text-muted-foreground",
+ )}
+ >
+ {field.value ? (
+ format(new Date(field.value), "PPP")
+ ) : (
+ <span>Pick a date</span>
+ )}
+ <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+ </Button>
+ </PopoverTrigger>
+ </FormControl>
+ <PopoverContent
+ className="pointer-events-auto w-auto p-0"
+ align="start"
+ >
+ <Calendar
+ mode="single"
+ selected={
+ field.value ? new Date(field.value) : undefined
+ }
+ onSelect={(date) => {
+ if (!date) {
+ field.onChange("");
+ return;
+ }
+ // Convert to ISO string and take only the date part (YYYY-MM-DD)
+ const dateString = date
+ .toISOString()
+ .split("T")[0];
+ field.onChange(dateString);
+ }}
+ disabled={(date) => {
+ const today = new Date();
+ today.setHours(0, 0, 0, 0);
+ const compareDate = new Date(date);
+ compareDate.setHours(0, 0, 0, 0);
+ return compareDate < today;
+ }}
+ initialFocus
+ />
+ </PopoverContent>
+ </Popover>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <DialogFooter className="mt-4">
+ <Button
+ variant="outline"
+ type="button"
+ onClick={() => setCreateDialogOpen(false)}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" disabled={isPending}>
+ Create
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </DialogContent>
+ </Dialog>
</FormCardFooter>
<AlertDialog open={!!result} onOpenChange={() => setResult(null)}>
<AlertDialogContent>
<AlertDialogHeader>
- <AlertDialogTitle>API Key</AlertDialogTitle>
+ <AlertDialogTitle>API Key Created</AlertDialogTitle>
<AlertDialogDescription>
Ensure you copy your API key before closing this dialog. You will
not see it again.
</AlertDialogDescription>
</AlertDialogHeader>
- <div className="flex items-center gap-2 rounded-md border bg-muted/50 px-3 py-2">
- <code className="flex-1 font-mono text-sm">{result?.key}</code>
+ <div>
<Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
+ variant="outline"
+ size="sm"
onClick={() => {
- copy(result?.key || "", { withToast: true });
+ copy(result?.token || "", {
+ successMessage: "Copied API key to clipboard",
+ });
}}
>
- <Copy className="h-4 w-4" />
+ <code>{result?.token}</code>
+ {isCopied ? (
+ <Check size={16} className="text-muted-foreground" />
+ ) : (
+ <Copy size={16} className="text-muted-foreground" />
+ )}
</Button>
</div>
<AlertDialogFooter>
- <Button
- onClick={() => {
- refetch();
- setResult(null);
- }}
- >
- Done
- </Button>
+ <Button onClick={() => setResult(null)}>Done</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.ts
index 8adeb357b..da650a81c 100644
--- a/apps/dashboard/src/lib/trpc/shared.ts
+++ b/apps/dashboard/src/lib/trpc/shared.ts
@@ -11,7 +11,7 @@ const getBaseUrl = () => {
return "http://localhost:3000"; // Local dev and Docker (internal calls)
};
-const lambdas = ["stripeRouter", "emailRouter"];
+const lambdas = ["stripeRouter", "emailRouter", "apiKeyRouter"];
export const endingLink = (opts?: {
fetch?: typeof fetch;
diff --git a/apps/server/src/libs/middlewares/auth.ts b/apps/server/src/libs/middlewares/auth.ts
index a84439f9a..e4ee60e5b 100644
--- a/apps/server/src/libs/middlewares/auth.ts
+++ b/apps/server/src/libs/middlewares/auth.ts
@@ -5,8 +5,16 @@ import type { Context, Next } from "hono";
import { env } from "@/env";
import { OpenStatusApiError } from "@/libs/errors";
import type { Variables } from "@/types";
+import { getLogger } from "@logtape/logtape";
import { db, eq } from "@openstatus/db";
import { selectWorkspaceSchema, workspace } from "@openstatus/db/src/schema";
+import { apiKey } from "@openstatus/db/src/schema/api-keys";
+import {
+ shouldUpdateLastUsed,
+ verifyApiKeyHash,
+} from "@openstatus/db/src/utils/api-key";
+
+const logger = getLogger("api-server");
export async function authMiddleware(
c: Context<{ Variables: Variables }, "/*">,
@@ -78,20 +86,70 @@ async function validateKey(key: string): Promise<{
}> {
if (env.NODE_ENV === "production") {
/**
- * The Unkey api key starts with `os_` - that's how we can differentiate if we
- * want to roll out our own key verification in the future.
- * > We cannot use `os_` as a prefix for our own keys.
+ * Both custom and Unkey API keys use the `os_` prefix for seamless transition.
+ * Custom keys are checked first in the database, then falls back to Unkey.
*/
if (key.startsWith("os_")) {
+ // Validate token format before database query
+ if (!/^os_[a-f0-9]{32}$/.test(key)) {
+ return {
+ result: { valid: false },
+ error: { message: "Invalid API Key format" },
+ };
+ }
+
+ // 1. Try custom DB first
+ const prefix = key.slice(0, 11); // "os_" (3 chars) + 8 hex chars = 11 total
+ const customKey = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.prefix, prefix))
+ .get();
+
+ if (customKey) {
+ // Verify hash using bcrypt-compatible verification
+ if (!(await verifyApiKeyHash(key, customKey.hashedToken))) {
+ return {
+ result: { valid: false },
+ error: { message: "Invalid API Key" },
+ };
+ }
+ // Check expiration
+ if (customKey.expiresAt && customKey.expiresAt < new Date()) {
+ return {
+ result: { valid: false },
+ error: { message: "API Key expired" },
+ };
+ }
+
+ // Update lastUsedAt (debounced)
+ if (shouldUpdateLastUsed(customKey.lastUsedAt)) {
+ await db
+ .update(apiKey)
+ .set({ lastUsedAt: new Date() })
+ .where(eq(apiKey.id, customKey.id));
+ }
+ return {
+ result: { valid: true, ownerId: String(customKey.workspaceId) },
+ };
+ }
+
+ // 2. Fall back to Unkey (transition period)
const unkey = new UnkeyCore({ rootKey: env.UNKEY_TOKEN });
const res = await keysVerifyKey(unkey, { key });
if (!res.ok) {
- console.error("Unkey Error", res.error?.message);
+ logger.error("Unkey Error {*}", { ...res.error });
return {
result: { valid: false, ownerId: undefined },
error: { message: "Invalid API verification" },
};
}
+ // Add deprecation header when Unkey key is used
+ if (res.value.data.valid) {
+ logger.info("Unkey key used - Workspace: {workspaceId}", {
+ workspace: res.value.data.identity?.externalId,
+ });
+ }
return {
result: {
valid: res.value.data.valid,
diff --git a/package.json b/package.json
index 5b3f3863d..ff485e88e 100644
--- a/package.json
+++ b/package.json
@@ -32,11 +32,11 @@
},
"packageManager": "[email protected]",
"pnpm": {
- "onlyBuiltDependencies": ["@sentry/cli", "@swc/core", "sharp"],
- "overrides": {
- "@react-email/preview-server": "npm:[email protected]"
- }
+ "onlyBuiltDependencies": ["@sentry/cli", "@swc/core", "sharp"]
},
"name": "openstatus",
- "workspaces": ["apps/*", "packages/**/*"]
+ "workspaces": ["apps/*", "packages/**/*", "packages/config/*"],
+ "overrides": {
+ "@react-email/preview-server": "npm:[email protected]"
+ }
}
diff --git a/packages/api/src/edge.ts b/packages/api/src/edge.ts
index 57e3f9136..11650fc0a 100644
--- a/packages/api/src/edge.ts
+++ b/packages/api/src/edge.ts
@@ -1,4 +1,3 @@
-import { apiKeyRouter } from "./router/apiKey";
import { blobRouter } from "./router/blob";
import { checkerRouter } from "./router/checker";
import { domainRouter } from "./router/domain";
@@ -23,7 +22,6 @@ import { createTRPCRouter } from "./trpc";
// Deployed to /trpc/edge/**
export const edgeRouter = createTRPCRouter({
- apiKey: apiKeyRouter,
workspace: workspaceRouter,
monitor: monitorRouter,
page: pageRouter,
diff --git a/packages/api/src/lambda.ts b/packages/api/src/lambda.ts
index d384b4fb0..384f0bae5 100644
--- a/packages/api/src/lambda.ts
+++ b/packages/api/src/lambda.ts
@@ -1,3 +1,4 @@
+import { apiKeyRouter } from "./router/apiKey";
import { emailRouter } from "./router/email";
import { stripeRouter } from "./router/stripe";
import { createTRPCRouter } from "./trpc";
@@ -5,6 +6,7 @@ import { createTRPCRouter } from "./trpc";
export const lambdaRouter = createTRPCRouter({
stripeRouter: stripeRouter,
emailRouter: emailRouter,
+ apiKeyRouter: apiKeyRouter,
});
export { stripe } from "./router/stripe/shared";
diff --git a/packages/api/src/router/apiKey.ts b/packages/api/src/router/apiKey.ts
index a874702b9..1935e3ce9 100644
--- a/packages/api/src/router/apiKey.ts
+++ b/packages/api/src/router/apiKey.ts
@@ -1,24 +1,24 @@
-import { UnkeyCore } from "@unkey/api/core";
-import { apisListKeys } from "@unkey/api/funcs/apisListKeys";
-import { keysCreateKey } from "@unkey/api/funcs/keysCreateKey";
-import { keysDeleteKey } from "@unkey/api/funcs/keysDeleteKey";
import { z } from "zod";
import { Events } from "@openstatus/analytics";
import { db, eq } from "@openstatus/db";
import { user, usersToWorkspaces, workspace } from "@openstatus/db/src/schema";
+import { createApiKeySchema } from "@openstatus/db/src/schema/api-keys/validation";
import { TRPCError } from "@trpc/server";
-import { env } from "../env";
+import {
+ createApiKey as createCustomApiKey,
+ getApiKeys,
+ revokeApiKey,
+} from "../service/apiKey";
import { createTRPCRouter, protectedProcedure } from "../trpc";
export const apiKeyRouter = createTRPCRouter({
create: protectedProcedure
.meta({ track: Events.CreateAPI })
- .input(z.object({ ownerId: z.number() }))
+ .input(createApiKeySchema)
.mutation(async ({ input, ctx }) => {
- const unkey = new UnkeyCore({ rootKey: env.UNKEY_TOKEN });
-
+ // Verify user has access to the workspace
const allowedWorkspaces = await db
.select()
.from(usersToWorkspaces)
@@ -29,62 +29,71 @@ export const apiKeyRouter = createTRPCRouter({
const allowedIds = allowedWorkspaces.map((i) => i.workspace.id);
- if (!allowedIds.includes(input.ownerId)) {
+ if (!allowedIds.includes(ctx.workspace.id)) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Unauthorized",
});
}
- const res = await keysCreateKey(unkey, {
- apiId: env.UNKEY_API_ID,
- externalId: String(input.ownerId),
- prefix: "os",
- });
-
- if (!res.ok) {
- throw new TRPCError({
- code: "BAD_REQUEST",
- message: res.error.message,
- });
- }
-
- return res.value.data;
+ // Create the API key using the custom service
+ const { token, key } = await createCustomApiKey(
+ ctx.workspace.id,
+ ctx.user.id,
+ input.name,
+ input.description,
+ input.expiresAt,
+ );
+
+ // Return both the key details and the full token (one-time display)
+ return {
+ token,
+ key,
+ };
}),
revoke: protectedProcedure
.meta({ track: Events.RevokeAPI })
- .input(z.object({ keyId: z.string() }))
- .mutation(async ({ input }) => {
- const unkey = new UnkeyCore({ rootKey: env.UNKEY_TOKEN });
-
- const res = await keysDeleteKey(unkey, { keyId: input.keyId });
+ .input(z.object({ keyId: z.number() }))
+ .mutation(async ({ input, ctx }) => {
+ // Revoke the key with workspace ownership verification
+ const success = await revokeApiKey(input.keyId, ctx.workspace.id);
- if (!res.ok) {
+ if (!success) {
throw new TRPCError({
- code: "BAD_REQUEST",
- message: res.error.message,
+ code: "NOT_FOUND",
+ message: "API key not found or unauthorized",
});
}
- return res.value;
+ return;
}),
- get: protectedProcedure.query(async ({ ctx }) => {
- const unkey = new UnkeyCore({ rootKey: env.UNKEY_TOKEN });
-
- const res = await apisListKeys(unkey, {
- externalId: String(ctx.workspace.id),
- apiId: env.UNKEY_API_ID,
- });
-
- if (!res.ok) {
- throw new TRPCError({
- code: "BAD_REQUEST",
- message: res.error.message,
- });
- }
-
- return res.value.data[0];
+ getAll: protectedProcedure.query(async ({ ctx }) => {
+ // Get all API keys for the workspace
+ const keys = await getApiKeys(ctx.workspace.id);
+
+ // Fetch user information for each key's creator
+ const keysWithUserInfo = await Promise.all(
+ keys.map(async (key) => {
+ const creator = await db
+ .select({
+ id: user.id,
+ email: user.email,
+ firstName: user.firstName,
+ lastName: user.lastName,
+ })
+ .from(user)
+ .where(eq(user.id, key.createdById))
+ .get();
+
+ return {
+ ...key,
+ createdBy: creator,
+ };
+ }),
+ );
+
+ return keysWithUserInfo;
}),
});
diff --git a/packages/api/src/service/apiKey.test.ts b/packages/api/src/service/apiKey.test.ts
new file mode 100644
index 000000000..1ce21a821
--- /dev/null
+++ b/packages/api/src/service/apiKey.test.ts
@@ -0,0 +1,434 @@
+import { afterAll, beforeAll, describe, expect, test } from "bun:test";
+
+import { db, eq } from "@openstatus/db";
+import { apiKey } from "@openstatus/db/src/schema";
+import { verifyApiKeyHash } from "@openstatus/db/src/utils/api-key";
+
+import {
+ createApiKey,
+ getApiKeys,
+ revokeApiKey,
+ updateLastUsed,
+ verifyApiKey,
+} from "./apiKey";
+
+// Test data setup
+let testWorkspaceId: number;
+let testUserId: number;
+let testApiKeyId: number;
+let testToken: string;
+
+beforeAll(async () => {
+ // Clean up any existing test data
+ await db.delete(apiKey).where(eq(apiKey.name, "Test API Key"));
+ await db.delete(apiKey).where(eq(apiKey.name, "Test Key with Description"));
+ await db.delete(apiKey).where(eq(apiKey.name, "Test Key with Expiration"));
+
+ // Use existing test workspace and user from seed data
+ testWorkspaceId = 1;
+ testUserId = 1;
+});
+
+afterAll(async () => {
+ // Clean up test data
+ await db.delete(apiKey).where(eq(apiKey.name, "Test API Key"));
+ await db.delete(apiKey).where(eq(apiKey.name, "Test Key with Description"));
+ await db.delete(apiKey).where(eq(apiKey.name, "Test Key with Expiration"));
+});
+
+describe("createApiKey", () => {
+ test("should create API key with minimal parameters", async () => {
+ const result = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Test API Key",
+ );
+
+ expect(result).toBeDefined();
+ expect(result.token).toMatch(/^os_[a-f0-9]{32}$/);
+ expect(result.key).toMatchObject({
+ name: "Test API Key",
+ workspaceId: testWorkspaceId,
+ createdById: testUserId,
+ description: null,
+ expiresAt: null,
+ });
+ expect(result.key.prefix).toBe(result.token.slice(0, 11));
+ expect(await verifyApiKeyHash(result.token, result.key.hashedToken)).toBe(
+ true,
+ );
+
+ // Save for later tests
+ testApiKeyId = result.key.id;
+ testToken = result.token;
+ });
+
+ test("should create API key with description", async () => {
+ const description = "This is a test API key for integration testing";
+ const result = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Test Key with Description",
+ description,
+ );
+
+ expect(result.key.description).toBe(description);
+ });
+
+ test("should create API key with expiration", async () => {
+ const expiresAt = new Date(Date.now() + 86400000); // 1 day from now
+ const result = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Test Key with Expiration",
+ undefined,
+ expiresAt,
+ );
+
+ // SQLite stores timestamps with second precision, so compare with tolerance
+ expect(result.key.expiresAt?.getTime()).toBeCloseTo(
+ expiresAt.getTime(),
+ -4,
+ );
+ });
+
+ test("should create API key with both description and expiration", async () => {
+ const description = "Full featured key";
+ const expiresAt = new Date(Date.now() + 86400000);
+ const result = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Full Featured Key",
+ description,
+ expiresAt,
+ );
+
+ expect(result.key).toMatchObject({
+ name: "Full Featured Key",
+ description,
+ expiresAt,
+ });
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, result.key.id));
+ });
+
+ test("should generate unique tokens", async () => {
+ const result1 = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Unique Key 1",
+ );
+ const result2 = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Unique Key 2",
+ );
+
+ expect(result1.token).not.toBe(result2.token);
+ expect(result1.key.prefix).not.toBe(result2.key.prefix);
+ expect(result1.key.hashedToken).not.toBe(result2.key.hashedToken);
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, result1.key.id));
+ await db.delete(apiKey).where(eq(apiKey.id, result2.key.id));
+ });
+});
+
+describe("verifyApiKey", () => {
+ test("should verify valid API key", async () => {
+ const result = await verifyApiKey(testToken);
+
+ expect(result).not.toBeNull();
+ expect(result).toMatchObject({
+ id: testApiKeyId,
+ name: "Test API Key",
+ workspaceId: testWorkspaceId,
+ createdById: testUserId,
+ });
+ });
+
+ test("should return null for invalid token format", async () => {
+ const invalidToken = "os_invalid";
+ const result = await verifyApiKey(invalidToken);
+
+ expect(result).toBeNull();
+ });
+
+ test("should return null for non-existent token", async () => {
+ const nonExistentToken = `os_${"a".repeat(32)}`;
+ const result = await verifyApiKey(nonExistentToken);
+
+ expect(result).toBeNull();
+ });
+
+ test("should return null for token with incorrect hash", async () => {
+ // Create a token with same prefix but different hash
+ const wrongToken = testToken.slice(0, 11) + "0".repeat(24);
+ const result = await verifyApiKey(wrongToken);
+
+ expect(result).toBeNull();
+ });
+
+ test("should return null for expired token", async () => {
+ // Create an expired key
+ const expiredDate = new Date(Date.now() - 86400000); // 1 day ago
+ const expiredKey = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Expired Key",
+ undefined,
+ expiredDate,
+ );
+
+ const result = await verifyApiKey(expiredKey.token);
+
+ expect(result).toBeNull();
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, expiredKey.key.id));
+ });
+
+ test("should verify token that expires in the future", async () => {
+ // Create a key that expires in the future
+ const futureDate = new Date(Date.now() + 86400000); // 1 day from now
+ const futureKey = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Future Expiry Key",
+ undefined,
+ futureDate,
+ );
+
+ const result = await verifyApiKey(futureKey.token);
+
+ expect(result).not.toBeNull();
+ expect(result?.id).toBe(futureKey.key.id);
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, futureKey.key.id));
+ });
+});
+
+describe("revokeApiKey", () => {
+ test("should revoke API key successfully", async () => {
+ // Create a key to revoke
+ const keyToRevoke = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Key to Revoke",
+ );
+
+ const result = await revokeApiKey(keyToRevoke.key.id, testWorkspaceId);
+
+ expect(result).toBe(true);
+
+ // Verify key is deleted
+ const deletedKey = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.id, keyToRevoke.key.id))
+ .get();
+
+ expect(deletedKey).toBeUndefined();
+ });
+
+ test("should return false for non-existent key", async () => {
+ const result = await revokeApiKey(999999, testWorkspaceId);
+
+ expect(result).toBe(false);
+ });
+
+ test("should return false when workspace ID doesn't match", async () => {
+ // Create a key
+ const key = await createApiKey(testWorkspaceId, testUserId, "Test Key");
+
+ // Try to revoke with wrong workspace ID
+ const result = await revokeApiKey(key.key.id, 999);
+
+ expect(result).toBe(false);
+
+ // Verify key still exists
+ const stillExists = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.id, key.key.id))
+ .get();
+
+ expect(stillExists).toBeDefined();
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key.key.id));
+ });
+});
+
+describe("getApiKeys", () => {
+ test("should get all API keys for a workspace", async () => {
+ // Create multiple keys
+ const key1 = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Workspace Key 1",
+ );
+ const key2 = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Workspace Key 2",
+ );
+ const key3 = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Workspace Key 3",
+ );
+
+ const keys = await getApiKeys(testWorkspaceId);
+
+ // Should include at least the 3 keys we just created plus the test key from earlier
+ expect(keys.length).toBeGreaterThanOrEqual(4);
+ expect(keys.some((k) => k.name === "Workspace Key 1")).toBe(true);
+ expect(keys.some((k) => k.name === "Workspace Key 2")).toBe(true);
+ expect(keys.some((k) => k.name === "Workspace Key 3")).toBe(true);
+
+ // All keys should belong to the test workspace
+ keys.forEach((key) => {
+ expect(key.workspaceId).toBe(testWorkspaceId);
+ });
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key1.key.id));
+ await db.delete(apiKey).where(eq(apiKey.id, key2.key.id));
+ await db.delete(apiKey).where(eq(apiKey.id, key3.key.id));
+ });
+
+ test("should return empty array for workspace with no keys", async () => {
+ // Use a non-existent workspace ID
+ const keys = await getApiKeys(999999);
+
+ expect(keys).toEqual([]);
+ });
+
+ test("should not include keys from other workspaces", async () => {
+ // Assuming there might be other workspaces, verify isolation
+ const keys = await getApiKeys(testWorkspaceId);
+
+ keys.forEach((key) => {
+ expect(key.workspaceId).toBe(testWorkspaceId);
+ });
+ });
+});
+
+describe("updateLastUsed", () => {
+ test("should update lastUsedAt when never used", async () => {
+ const key = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Never Used Key",
+ );
+
+ const result = await updateLastUsed(key.key.id, null);
+
+ expect(result).toBe(true);
+
+ // Verify the update
+ const updatedKey = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.id, key.key.id))
+ .get();
+
+ expect(updatedKey?.lastUsedAt).not.toBeNull();
+ expect(updatedKey?.lastUsedAt).toBeInstanceOf(Date);
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key.key.id));
+ });
+
+ test("should update lastUsedAt when debounce period has passed", async () => {
+ const key = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Debounce Test Key",
+ );
+
+ // Set lastUsedAt to 10 minutes ago (beyond 5-minute debounce)
+ const tenMinutesAgo = new Date(Date.now() - 10 * 60 * 1000);
+ await db
+ .update(apiKey)
+ .set({ lastUsedAt: tenMinutesAgo })
+ .where(eq(apiKey.id, key.key.id));
+
+ const result = await updateLastUsed(key.key.id, tenMinutesAgo);
+
+ expect(result).toBe(true);
+
+ // Verify the update
+ const updatedKey = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.id, key.key.id))
+ .get();
+
+ expect(updatedKey?.lastUsedAt?.getTime()).toBeGreaterThan(
+ tenMinutesAgo.getTime(),
+ );
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key.key.id));
+ });
+
+ test("should not update lastUsedAt within debounce period", async () => {
+ const key = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Recent Use Key",
+ );
+
+ // Set lastUsedAt to 2 minutes ago (within 5-minute debounce)
+ const twoMinutesAgo = new Date(Date.now() - 2 * 60 * 1000);
+ await db
+ .update(apiKey)
+ .set({ lastUsedAt: twoMinutesAgo })
+ .where(eq(apiKey.id, key.key.id));
+
+ const result = await updateLastUsed(key.key.id, twoMinutesAgo);
+
+ expect(result).toBe(false);
+
+ // Verify no update occurred (compare with tolerance due to SQLite timestamp precision)
+ const updatedKey = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.id, key.key.id))
+ .get();
+
+ expect(updatedKey?.lastUsedAt?.getTime()).toBeCloseTo(
+ twoMinutesAgo.getTime(),
+ -4,
+ );
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key.key.id));
+ });
+
+ test("should update at exactly 5 minutes (boundary test)", async () => {
+ const key = await createApiKey(
+ testWorkspaceId,
+ testUserId,
+ "Boundary Test Key",
+ );
+
+ // Set lastUsedAt to exactly 5 minutes and 1ms ago
+ const fiveMinutesAgo = new Date(Date.now() - (5 * 60 * 1000 + 1));
+ await db
+ .update(apiKey)
+ .set({ lastUsedAt: fiveMinutesAgo })
+ .where(eq(apiKey.id, key.key.id));
+
+ const result = await updateLastUsed(key.key.id, fiveMinutesAgo);
+
+ expect(result).toBe(true);
+
+ // Clean up
+ await db.delete(apiKey).where(eq(apiKey.id, key.key.id));
+ });
+});
diff --git a/packages/api/src/service/apiKey.ts b/packages/api/src/service/apiKey.ts
new file mode 100644
index 000000000..9150b92f1
--- /dev/null
+++ b/packages/api/src/service/apiKey.ts
@@ -0,0 +1,149 @@
+import { eq } from "@openstatus/db";
+import { db } from "@openstatus/db";
+import { apiKey } from "@openstatus/db/src/schema";
+import {
+ shouldUpdateLastUsed as checkShouldUpdateLastUsed,
+ generateApiKey as generateKey,
+ verifyApiKeyHash,
+} from "@openstatus/db/src/utils/api-key";
+
+/**
+ * Creates a new API key for a workspace
+ * @param workspaceId - The workspace ID
+ * @param createdById - The ID of the user creating the key
+ * @param name - The name of the API key
+ * @param description - Optional description for the key
+ * @param expiresAt - Optional expiration date
+ * @returns The full token (only shown once) and the created key details
+ */
+export async function createApiKey(
+ workspaceId: number,
+ createdById: number,
+ name: string,
+ description?: string,
+ expiresAt?: Date,
+): Promise<{ token: string; key: typeof apiKey.$inferSelect }> {
+ const { token, prefix, hash } = await generateKey();
+
+ const [key] = await db
+ .insert(apiKey)
+ .values({
+ name,
+ description,
+ prefix,
+ hashedToken: hash,
+ workspaceId,
+ createdById,
+ expiresAt,
+ })
+ .returning();
+
+ if (!key) {
+ throw new Error("Failed to create API key");
+ }
+
+ return { token, key };
+}
+
+/**
+ * Verifies an API key token
+ * @param token - The API key token to verify
+ * @returns The API key details if valid, null otherwise
+ */
+export async function verifyApiKey(
+ token: string,
+): Promise<typeof apiKey.$inferSelect | null> {
+ // Validate token format before database query
+ if (!/^os_[a-f0-9]{32}$/.test(token)) {
+ return null;
+ }
+
+ // Extract prefix from token
+ const prefix = token.slice(0, 11); // "os_" + 8 chars = 11 total
+
+ // Look up key by prefix
+ const key = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.prefix, prefix))
+ .get();
+
+ if (!key) {
+ return null;
+ }
+
+ // Verify hash using bcrypt-compatible verification
+ if (!(await verifyApiKeyHash(token, key.hashedToken))) {
+ return null;
+ }
+
+ // Check expiration
+ if (key.expiresAt && key.expiresAt < new Date()) {
+ return null;
+ }
+
+ return key;
+}
+
+/**
+ * Revokes (deletes) an API key
+ * @param id - The API key ID
+ * @param workspaceId - The workspace ID for ownership verification
+ * @returns True if successfully revoked, false otherwise
+ */
+export async function revokeApiKey(
+ id: number,
+ workspaceId: number,
+): Promise<boolean> {
+ // First, verify the key exists and belongs to the workspace
+ const key = await db.select().from(apiKey).where(eq(apiKey.id, id)).get();
+
+ if (!key || key.workspaceId !== workspaceId) {
+ return false;
+ }
+
+ // Delete the key
+ await db.delete(apiKey).where(eq(apiKey.id, id));
+
+ return true;
+}
+
+/**
+ * Gets all API keys for a workspace
+ * @param workspaceId - The workspace ID
+ * @returns Array of API keys for the workspace
+ */
+export async function getApiKeys(
+ workspaceId: number,
+): Promise<Array<typeof apiKey.$inferSelect>> {
+ const keys = await db
+ .select()
+ .from(apiKey)
+ .where(eq(apiKey.workspaceId, workspaceId))
+ .all();
+
+ return keys;
+}
+
+/**
+ * Updates the lastUsedAt timestamp for an API key (with debouncing)
+ * @param id - The API key ID
+ * @param lastUsedAt - The current lastUsedAt value (or null)
+ * @returns True if updated, false if skipped due to debounce
+ */
+export async function updateLastUsed(
+ id: number,
+ lastUsedAt: Date | null,
+): Promise<boolean> {
+ // Check if update is needed (5-minute debounce)
+ if (!checkShouldUpdateLastUsed(lastUsedAt)) {
+ return false;
+ }
+
+ await db
+ .update(apiKey)
+ .set({ lastUsedAt: new Date() })
+ .where(eq(apiKey.id, id));
+
+ return true;
+}
diff --git a/packages/db/drizzle/0052_illegal_killraven.sql b/packages/db/drizzle/0052_illegal_killraven.sql
new file mode 100644
index 000000000..4248ee56d
--- /dev/null
+++ b/packages/db/drizzle/0052_illegal_killraven.sql
@@ -0,0 +1,18 @@
+CREATE TABLE `api_key` (
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
+ `name` text NOT NULL,
+ `description` text,
+ `prefix` text NOT NULL,
+ `hashed_token` text NOT NULL,
+ `workspace_id` integer NOT NULL,
+ `created_by_id` integer NOT NULL,
+ `created_at` integer DEFAULT (strftime('%s', 'now')),
+ `expires_at` integer,
+ `last_used_at` integer,
+ FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE cascade,
+ FOREIGN KEY (`created_by_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
+);
+--> statement-breakpoint
+CREATE UNIQUE INDEX `api_key_prefix_unique` ON `api_key` (`prefix`);--> statement-breakpoint
+CREATE UNIQUE INDEX `api_key_hashed_token_unique` ON `api_key` (`hashed_token`);--> statement-breakpoint
+CREATE INDEX `api_key_prefix_idx` ON `api_key` (`prefix`);
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/0052_snapshot.json b/packages/db/drizzle/meta/0052_snapshot.json
new file mode 100644
index 000000000..00c51e245
--- /dev/null
+++ b/packages/db/drizzle/meta/0052_snapshot.json
@@ -0,0 +1,3071 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "cc596587-5474-42a7-b638-1b7c771fbc5e",
+ "prevId": "e8d9889c-8d28-4311-83e6-9fd28c840595",
+ "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
+ },
+ "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 394ef1375..684379f9c 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -365,6 +365,13 @@
"when": 1767362130713,
"tag": "0051_fuzzy_red_hulk",
"breakpoints": true
+ },
+ {
+ "idx": 52,
+ "version": "6",
+ "when": 1767797078062,
+ "tag": "0052_illegal_killraven",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/packages/db/package.json b/packages/db/package.json
index d637c64dd..ebe598ab1 100644
--- a/packages/db/package.json
+++ b/packages/db/package.json
@@ -18,12 +18,14 @@
"@openstatus/regions": "workspace:*",
"@openstatus/theme-store": "workspace:*",
"@t3-oss/env-core": "0.13.10",
+ "bcryptjs": "3.0.3",
"drizzle-orm": "0.44.4",
"drizzle-zod": "0.8.3",
"zod": "4.1.13"
},
"devDependencies": {
"@openstatus/tsconfig": "workspace:*",
+ "@types/bcryptjs": "3.0.0",
"@types/node": "22.10.2",
"drizzle-kit": "0.31.4",
"next-auth": "5.0.0-beta.29",
diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts
index bc52de7eb..2e05a8b86 100644
--- a/packages/db/src/index.ts
+++ b/packages/db/src/index.ts
@@ -1,6 +1,5 @@
export * as schema from "./schema";
export * from "drizzle-orm";
export * from "./db";
-export * from "./utils";
// doing this because the external module not working see : https://github.com/vercel/next.js/issues/43433
// export * from "./sync-db";
diff --git a/packages/db/src/schema/api-keys/api_key.ts b/packages/db/src/schema/api-keys/api_key.ts
new file mode 100644
index 000000000..b9ff5bc4a
--- /dev/null
+++ b/packages/db/src/schema/api-keys/api_key.ts
@@ -0,0 +1,41 @@
+import { relations, sql } from "drizzle-orm";
+import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
+
+import { user } from "../users";
+import { workspace } from "../workspaces";
+
+export const apiKey = sqliteTable(
+ "api_key",
+ {
+ id: integer("id").primaryKey({ autoIncrement: true }),
+ name: text("name").notNull(),
+ description: text("description"),
+ prefix: text("prefix").notNull().unique(),
+ hashedToken: text("hashed_token").notNull().unique(),
+ workspaceId: integer("workspace_id")
+ .notNull()
+ .references(() => workspace.id, { onDelete: "cascade" }),
+ createdById: integer("created_by_id")
+ .notNull()
+ .references(() => user.id, { onDelete: "cascade" }),
+ createdAt: integer("created_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`,
+ ),
+ expiresAt: integer("expires_at", { mode: "timestamp" }),
+ lastUsedAt: integer("last_used_at", { mode: "timestamp" }),
+ },
+ (table) => ({
+ prefixIdx: index("api_key_prefix_idx").on(table.prefix),
+ }),
+);
+
+export const apiKeyRelations = relations(apiKey, ({ one }) => ({
+ workspace: one(workspace, {
+ fields: [apiKey.workspaceId],
+ references: [workspace.id],
+ }),
+ createdBy: one(user, {
+ fields: [apiKey.createdById],
+ references: [user.id],
+ }),
+}));
diff --git a/packages/db/src/schema/api-keys/index.ts b/packages/db/src/schema/api-keys/index.ts
new file mode 100644
index 000000000..33288c277
--- /dev/null
+++ b/packages/db/src/schema/api-keys/index.ts
@@ -0,0 +1,2 @@
+export * from "./api_key";
+export * from "./validation";
diff --git a/packages/db/src/schema/api-keys/validation.ts b/packages/db/src/schema/api-keys/validation.ts
new file mode 100644
index 000000000..79938617c
--- /dev/null
+++ b/packages/db/src/schema/api-keys/validation.ts
@@ -0,0 +1,22 @@
+import { createInsertSchema, createSelectSchema } from "drizzle-zod";
+import { z } from "zod";
+
+import { apiKey } from "./api_key";
+
+export const insertApiKeySchema = createInsertSchema(apiKey, {
+ name: z.string().min(1, "Name is required"),
+ description: z.string().optional(),
+ expiresAt: z.date().optional(),
+});
+
+export const selectApiKeySchema = createSelectSchema(apiKey);
+
+export const createApiKeySchema = z.object({
+ name: z.string().min(1, "Name is required"),
+ description: z.string().optional(),
+ expiresAt: z.date().optional(),
+});
+
+export type InsertApiKey = z.infer<typeof insertApiKeySchema>;
+export type ApiKey = z.infer<typeof selectApiKeySchema>;
+export type CreateApiKeyInput = z.infer<typeof createApiKeySchema>;
diff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.ts
index 993cb5cb1..ad14091c4 100644
--- a/packages/db/src/schema/index.ts
+++ b/packages/db/src/schema/index.ts
@@ -18,3 +18,4 @@ export * from "./monitor_run";
export * from "./private_locations";
export * from "./monitor_groups";
export * from "./viewers";
+export * from "./api-keys";
diff --git a/packages/db/src/utils.ts b/packages/db/src/utils.ts
deleted file mode 100644
index 132b7a762..000000000
--- a/packages/db/src/utils.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import type { Column } from "drizzle-orm";
-import { sql } from "drizzle-orm";
-import type {
- SQLiteTable,
- SQLiteUpdateSetSource,
-} from "drizzle-orm/sqlite-core";
-
-export function conflictUpdateSet<TTable extends SQLiteTable>(
- table: TTable,
- columns: (keyof TTable["_"]["columns"] & keyof TTable)[],
-): SQLiteUpdateSetSource<TTable> {
- return Object.assign(
- {},
- ...columns.map((k) => ({
- [k]: sql`excluded.${(table[k] as Column).name}`,
- })),
- ) as SQLiteUpdateSetSource<TTable>;
-}
diff --git a/packages/db/src/utils/api-key.test.ts b/packages/db/src/utils/api-key.test.ts
new file mode 100644
index 000000000..448331a01
--- /dev/null
+++ b/packages/db/src/utils/api-key.test.ts
@@ -0,0 +1,194 @@
+import { describe, expect, it } from "bun:test";
+import {
+ generateApiKey,
+ hashApiKey,
+ shouldUpdateLastUsed,
+ verifyApiKeyHash,
+} from "./api-key";
+
+describe("API Key Utilities", () => {
+ describe("generateApiKey", () => {
+ it("should generate a token with correct format", async () => {
+ const { token, prefix, hash } = await generateApiKey();
+
+ // Token should start with "os_" and be 35 chars total (os_ + 32 hex)
+ expect(token).toMatch(/^os_[a-f0-9]{32}$/);
+ expect(token.length).toBe(35);
+ });
+
+ it("should generate a prefix with correct format", async () => {
+ const { prefix } = await generateApiKey();
+
+ // Prefix should be "os_" + 8 chars = 11 chars total
+ expect(prefix).toMatch(/^os_[a-f0-9]{8}$/);
+ expect(prefix.length).toBe(11);
+ });
+
+ it("should generate unique tokens", async () => {
+ const key1 = await generateApiKey();
+ const key2 = await generateApiKey();
+
+ expect(key1.token).not.toBe(key2.token);
+ expect(key1.hash).not.toBe(key2.hash);
+ });
+
+ it("should generate prefix from token start", async () => {
+ const { token, prefix } = await generateApiKey();
+
+ expect(token.slice(0, 11)).toBe(prefix);
+ });
+ });
+
+ describe("hashApiKey", () => {
+ it("should generate hash that can verify the token", async () => {
+ const { token, hash } = await generateApiKey();
+
+ expect(await verifyApiKeyHash(token, hash)).toBe(true);
+ });
+ });
+
+ describe("hashApiKey", () => {
+ it("should generate different hashes for different tokens", async () => {
+ const hash1 = await hashApiKey("os_token1");
+ const hash2 = await hashApiKey("os_token2");
+
+ expect(hash1).not.toBe(hash2);
+ });
+
+ it("should generate a valid bcrypt hash", async () => {
+ const hash = await hashApiKey("os_test_token");
+
+ // Bcrypt hashes start with $2a$, $2b$, or $2y$
+ expect(hash).toMatch(/^\$2[aby]\$/);
+ });
+
+ it("should generate hash that can verify the original token", async () => {
+ const token = "os_test_token_12345";
+ const hash = await hashApiKey(token);
+
+ expect(await verifyApiKeyHash(token, hash)).toBe(true);
+ });
+
+ it("should generate different hashes for same token on multiple calls", async () => {
+ const token = "os_same_token";
+ const hash1 = await hashApiKey(token);
+ const hash2 = await hashApiKey(token);
+
+ // bcrypt uses salt, so same input produces different hashes
+ expect(hash1).not.toBe(hash2);
+ // But both should verify the token
+ expect(await verifyApiKeyHash(token, hash1)).toBe(true);
+ expect(await verifyApiKeyHash(token, hash2)).toBe(true);
+ });
+ });
+
+ describe("verifyApiKeyHash", () => {
+ it("should return true for valid bcrypt hash with correct token", async () => {
+ const token = "os_valid_token_12345";
+ const hash = await hashApiKey(token);
+
+ expect(await verifyApiKeyHash(token, hash)).toBe(true);
+ });
+
+ it("should return false for valid bcrypt hash with wrong token", async () => {
+ const correctToken = "os_correct_token";
+ const wrongToken = "os_wrong_token";
+ const hash = await hashApiKey(correctToken);
+
+ expect(await verifyApiKeyHash(wrongToken, hash)).toBe(false);
+ });
+
+ it("should return false for non-bcrypt hash format", async () => {
+ const token = "os_test_token";
+ const invalidHash = "not_a_bcrypt_hash";
+
+ expect(await verifyApiKeyHash(token, invalidHash)).toBe(false);
+ });
+
+ it("should return false for SHA-256 hash format", async () => {
+ const token = "os_test_token";
+ // SHA-256 hashes are 64 hex characters
+ const sha256Hash =
+ "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8";
+
+ expect(await verifyApiKeyHash(token, sha256Hash)).toBe(false);
+ });
+
+ it("should return false for empty hash", async () => {
+ const token = "os_test_token";
+
+ expect(await verifyApiKeyHash(token, "")).toBe(false);
+ });
+
+ it("should return false for empty token with valid hash", async () => {
+ const hash = await hashApiKey("os_some_token");
+
+ expect(await verifyApiKeyHash("", hash)).toBe(false);
+ });
+
+ it("should handle bcrypt hashes with different cost factors", async () => {
+ const token = "os_test_token";
+ const hash = await hashApiKey(token);
+
+ // Should work regardless of the $2a$, $2b$, or $2y$ variant
+ expect(await verifyApiKeyHash(token, hash)).toBe(true);
+ });
+ });
+
+ describe("shouldUpdateLastUsed", () => {
+ it("should return true when lastUsedAt is null", () => {
+ expect(shouldUpdateLastUsed(null)).toBe(true);
+ });
+
+ it("should return true when enough time has passed", () => {
+ const sixMinutesAgo = new Date(Date.now() - 6 * 60 * 1000);
+ expect(shouldUpdateLastUsed(sixMinutesAgo, 5)).toBe(true);
+ });
+
+ it("should return false when not enough time has passed", () => {
+ const twoMinutesAgo = new Date(Date.now() - 2 * 60 * 1000);
+ expect(shouldUpdateLastUsed(twoMinutesAgo, 5)).toBe(false);
+ });
+
+ it("should respect custom debounce period", () => {
+ const threeMinutesAgo = new Date(Date.now() - 3 * 60 * 1000);
+ expect(shouldUpdateLastUsed(threeMinutesAgo, 2)).toBe(true);
+ expect(shouldUpdateLastUsed(threeMinutesAgo, 4)).toBe(false);
+ });
+
+ it("should return false when just updated", () => {
+ const justNow = new Date();
+ expect(shouldUpdateLastUsed(justNow, 5)).toBe(false);
+ });
+
+ it("should handle boundary case at exact debounce time", () => {
+ const exactlyFiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
+ // At exactly the debounce time, it should not update (needs to be > not >=)
+ expect(shouldUpdateLastUsed(exactlyFiveMinutesAgo, 5)).toBe(false);
+ });
+
+ it("should handle boundary case just after debounce time", () => {
+ const justOverFiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000 - 1);
+ expect(shouldUpdateLastUsed(justOverFiveMinutesAgo, 5)).toBe(true);
+ });
+
+ it("should use default debounce of 5 minutes when not specified", () => {
+ const fourMinutesAgo = new Date(Date.now() - 4 * 60 * 1000);
+ const sixMinutesAgo = new Date(Date.now() - 6 * 60 * 1000);
+
+ expect(shouldUpdateLastUsed(fourMinutesAgo)).toBe(false);
+ expect(shouldUpdateLastUsed(sixMinutesAgo)).toBe(true);
+ });
+
+ it("should handle zero debounce period", () => {
+ const oneSecondAgo = new Date(Date.now() - 1000);
+ expect(shouldUpdateLastUsed(oneSecondAgo, 0)).toBe(true);
+ });
+
+ it("should handle very long debounce periods", () => {
+ const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
+ expect(shouldUpdateLastUsed(oneHourAgo, 120)).toBe(false); // 2 hours
+ expect(shouldUpdateLastUsed(oneHourAgo, 30)).toBe(true); // 30 minutes
+ });
+ });
+});
diff --git a/packages/db/src/utils/api-key.ts b/packages/db/src/utils/api-key.ts
new file mode 100644
index 000000000..7b2de9083
--- /dev/null
+++ b/packages/db/src/utils/api-key.ts
@@ -0,0 +1,63 @@
+// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
+import crypto from "crypto";
+import bcrypt from "bcryptjs";
+
+/**
+ * Generates a new API key with token, prefix, and hash
+ * @returns Object containing the full token, prefix for lookup, and SHA-256 hash
+ */
+export async function generateApiKey(): Promise<{
+ token: string;
+ prefix: string;
+ hash: string;
+}> {
+ const randomBytes = crypto.randomBytes(16).toString("hex"); // 32 hex chars
+ const token = `os_${randomBytes}`;
+ const prefix = token.slice(0, 11); // "os_" (3 chars) + 8 hex chars = 11 total
+ const hash = await bcrypt.hash(token, 10);
+ return { token, prefix, hash };
+}
+
+/**
+ * Hashes an API key token using bcrypt
+ * @param token - The API key token to hash
+ * @returns The bcrypt hash of the token
+ */
+export async function hashApiKey(token: string): Promise<string> {
+ return bcrypt.hash(token, 10);
+}
+
+/**
+ * Verifies an API key token against a stored hash
+ * Supports both bcrypt hashes (new) and SHA-256 hashes (legacy) for migration
+ * @param token - The API key token to verify
+ * @param storedHash - The stored hash to verify against
+ * @returns True if the token matches the hash
+ */
+export async function verifyApiKeyHash(
+ token: string,
+ storedHash: string,
+): Promise<boolean> {
+ // Check if it's a bcrypt hash (starts with $2a$, $2b$, or $2y$)
+ if (storedHash.startsWith("$2")) {
+ return bcrypt.compare(token, storedHash);
+ }
+
+ // Unknown hash format
+ return false;
+}
+
+/**
+ * Determines if lastUsedAt should be updated based on debounce period
+ * @param lastUsedAt - The last time the key was used (or null)
+ * @param debounceMinutes - Minutes to wait before updating again (default: 5)
+ * @returns True if lastUsedAt should be updated
+ */
+export function shouldUpdateLastUsed(
+ lastUsedAt: Date | null,
+ debounceMinutes = 5,
+): boolean {
+ if (!lastUsedAt) return true;
+ const diffMs = Date.now() - lastUsedAt.getTime();
+ return diffMs > debounceMinutes * 60 * 1000;
+}
diff --git a/packages/db/src/utils/index.ts b/packages/db/src/utils/index.ts
new file mode 100644
index 000000000..c221d9427
--- /dev/null
+++ b/packages/db/src/utils/index.ts
@@ -0,0 +1 @@
+export * from "./api-key";
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 66fcb0d49..a7b707831 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4,9 +4,6 @@ settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
-overrides:
- '@react-email/preview-server': npm:[email protected]
-
importers:
.:
@@ -1323,6 +1320,9 @@ importers:
'@t3-oss/env-core':
specifier: 0.13.10
+ bcryptjs:
+ specifier: 3.0.3
+ version: 3.0.3
drizzle-orm:
specifier: 0.44.4
version: 0.44.4(@libsql/[email protected])(@opentelemetry/[email protected])(@types/[email protected])([email protected])
@@ -1336,6 +1336,9 @@ importers:
'@openstatus/tsconfig':
specifier: workspace:*
version: link:../tsconfig
+ '@types/bcryptjs':
+ specifier: 3.0.0
+ version: 3.0.0
'@types/node':
specifier: 22.10.2
version: 22.10.2
@@ -1389,8 +1392,8 @@ importers:
specifier: workspace:*
version: link:../tsconfig
'@react-email/preview-server':
- specifier: npm:[email protected]
+ specifier: 5.1.1
'@types/node':
specifier: 22.10.2
version: 22.10.2
@@ -5429,6 +5432,9 @@ packages:
peerDependencies:
react: ^18.0 || ^19.0 || ^19.0.0-rc
+ '@react-email/[email protected]':
+ resolution: {integrity: sha512-prMwnjWY9h57HL3MU2NRrj6ePjN7+A23vRwOjpVFczSW5InjitODFG1fRPKpdmIrRtVvj8XHdr7KDW0QXD8tow==}
+
'@react-email/[email protected]':
resolution: {integrity: sha512-aYK8q0IPkBXyMsbpMXgxazwHxYJxTrXrV95GFuu2HbEiIToMwSyUgb8HDFYwPqqfV03/jbwqlsXmFxsOd+VNaw==}
engines: {node: '>=20.0.0'}
@@ -6400,6 +6406,10 @@ packages:
resolution: {integrity: sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-WRZOuCuaz8UcZZE4R5HXTco2goQSI2XxjGY3hbM/xDvwmqFWd4ivooImsMx65OKM6CtNKbnZ5YL+YwAwK7c1dg==}
+ deprecated: This is a stub types definition. bcryptjs provides its own type definitions, so you do not need this installed.
+
resolution: {integrity: sha512-SQFof9H+LXeWNz8wDe7oN5zu7ket0qwMu5vZubW4GCJ8Kkeh6nBWUz87+KTz/G3Kqsrp0j/W253XJb3KMEeg3w==}
@@ -6922,6 +6932,10 @@ packages:
resolution: {integrity: sha512-9IIS3UPrvIa1Ej+lVDdDwO7zLehjqsaByECw0bu2RRGP73jALm6FYbzI5gWbgHLvNdkvfXB5YrSbocZdOS0c0w==}
+ resolution: {integrity: sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==}
+ hasBin: true
+
resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==}
@@ -15112,6 +15126,19 @@ snapshots:
marked: 15.0.12
react: 19.2.3
+ dependencies:
+ transitivePeerDependencies:
+ - '@babel/core'
+ - '@opentelemetry/api'
+ - '@playwright/test'
+ - babel-plugin-macros
+ - babel-plugin-react-compiler
+ - react
+ - react-dom
+ - sass
+
dependencies:
react: 19.2.3
@@ -16206,6 +16233,10 @@ snapshots:
dependencies:
'@babel/types': 7.28.5
+ '@types/[email protected]':
+ dependencies:
+ bcryptjs: 3.0.3
+
'@types/[email protected]': {}
@@ -16878,6 +16909,8 @@ snapshots:
is-alphanumerical: 2.0.1
is-decimal: 2.0.1
+