Skip to content

Open-source status page, incident response and uptime monitoring

📝 rename table (#487)

Thibault Le Ouay9c64fe2d57ed
diff --git a/apps/server/fly.toml b/apps/server/fly.toml
index 084e461d0..3afda9785 100644
--- a/apps/server/fly.toml
+++ b/apps/server/fly.toml
@@ -15,7 +15,6 @@ primary_region = "ams"
force_https = true
auto_stop_machines = false
auto_start_machines = false
- min_machines_running = 12
processes = ["app"]
[http_service.concurrency]
type = "requests"
diff --git a/apps/server/src/public/status.ts b/apps/server/src/public/status.ts
index d6b0b530c..aeb6b62e4 100644
--- a/apps/server/src/public/status.ts
+++ b/apps/server/src/public/status.ts
@@ -1,14 +1,14 @@
import { Hono } from "hono";
import { endTime, setMetric, startTime } from "hono/timing";
-import { db, eq } from "@openstatus/db";
+import { and, db, eq } from "@openstatus/db";
import {
- incident,
monitor,
- monitorsToIncidents,
monitorsToPages,
+ monitorsToStatusReport,
page,
- pagesToIncidents,
+ pagesToStatusReports,
+ statusReport,
} from "@openstatus/db/src/schema";
import { getMonitorList, Tinybird } from "@openstatus/tinybird";
import { Redis } from "@openstatus/upstash";
@@ -36,40 +36,44 @@ status.get("/:slug", async (c) => {
const { slug } = c.req.param();
const cache = await redis.get(slug);
+
if (cache) {
setMetric(c, "OpenStatus-Cache", "HIT");
-
return c.json({ status: cache });
}
startTime(c, "database");
- // { monitors, pages, monitors_to_pages }
+
const monitorData = await db
.select()
.from(monitorsToPages)
- .leftJoin(monitor, eq(monitorsToPages.monitorId, monitor.id))
+ .leftJoin(monitor, and(eq(monitorsToPages.monitorId, monitor.id)))
+ .leftJoin(
+ monitorsToStatusReport,
+ eq(monitor.id, monitorsToStatusReport.monitorId),
+ )
.leftJoin(
- monitorsToIncidents,
- eq(monitor.id, monitorsToIncidents.monitorId),
+ statusReport,
+ eq(monitorsToStatusReport.statusReportId, statusReport.id),
)
- .leftJoin(incident, eq(monitorsToIncidents.incidentId, incident.id))
.leftJoin(page, eq(monitorsToPages.pageId, page.id))
- .where(eq(page.slug, slug))
+ .where(eq(page.slug, slug)) // TODO: query only active monitors
.all();
- const pageIncidentData = await db
+ const pageStatusReportData = await db
.select()
- .from(pagesToIncidents)
- .leftJoin(incident, eq(pagesToIncidents.incidentId, incident.id))
- .leftJoin(page, eq(pagesToIncidents.pageId, page.id))
+ .from(pagesToStatusReports)
+ .leftJoin(
+ statusReport,
+ eq(pagesToStatusReports.statusReportId, statusReport.id),
+ )
+ .leftJoin(page, eq(pagesToStatusReports.pageId, page.id))
.where(eq(page.slug, slug))
.all();
- endTime(c, "database");
-
- const isIncident = [...pageIncidentData, ...monitorData].some((data) => {
- if (!data.incident) return false;
- return !["monitoring", "resolved"].includes(data.incident.status);
+ const isIncident = [...pageStatusReportData, ...monitorData].some((data) => {
+ if (!data.status_report) return false;
+ return !["monitoring", "resolved"].includes(data.status_report.status);
});
startTime(c, "clickhouse");
@@ -83,7 +87,7 @@ status.get("/:slug", async (c) => {
}),
);
endTime(c, "clickhouse");
- // { ok, count }
+
const data = lastMonitorPings.reduce(
(prev, curr) => {
if (curr.status === "fulfilled") {
diff --git a/apps/server/src/v1/index.ts b/apps/server/src/v1/index.ts
index 10cb90d7e..7d36a7725 100644
--- a/apps/server/src/v1/index.ts
+++ b/apps/server/src/v1/index.ts
@@ -3,10 +3,10 @@ import { logger } from "hono/logger";
import type { Plan } from "@openstatus/plans";
-import { incidentApi } from "./incident";
-import { incidenUpdateApi } from "./incidentUpdate";
import { middleware } from "./middleware";
import { monitorApi } from "./monitor";
+import { statusReportApi } from "./statusReport";
+import { statusReportUpdateApi } from "./statusReportUpdate";
export type Variables = {
workspaceId: string;
@@ -29,6 +29,6 @@ api.doc("/openapi", {
api.use("/*", middleware);
api.use("/*", logger());
api.route("/monitor", monitorApi);
-api.route("/incident_update", incidenUpdateApi);
+api.route("/status_report_update", statusReportUpdateApi);
-api.route("/incident", incidentApi);
+api.route("/status_report", statusReportApi);
diff --git a/apps/server/src/v1/incident.test.ts b/apps/server/src/v1/statusReport.test.ts
similarity index 59%
rename from apps/server/src/v1/incident.test.ts
rename to apps/server/src/v1/statusReport.test.ts
index 336cc9ab3..302953b06 100644
--- a/apps/server/src/v1/incident.test.ts
+++ b/apps/server/src/v1/statusReport.test.ts
@@ -2,8 +2,8 @@ import { expect, test } from "bun:test";
import { api } from ".";
-test("GET one incident update ", async () => {
- const res = await api.request("/incident/1", {
+test("GET one status report", async () => {
+ const res = await api.request("/status_report/1", {
headers: {
"x-openstatus-key": "1",
},
@@ -12,13 +12,14 @@ test("GET one incident update ", async () => {
expect(await res.json()).toMatchObject({
id: 1,
status: "investigating",
- title: "Test Incident",
- incident_updates: expect.any(Array),
+ title: "Test Status Report",
+ // TODO: discuss if we should return `updates` instead of `status_report_updates`
+ status_report_updates: expect.any(Array),
});
});
-test("create one incident ", async () => {
- const res = await api.request("/incident", {
+test("create one status report", async () => {
+ const res = await api.request("/status_report", {
method: "POST",
headers: {
"x-openstatus-key": "1",
@@ -27,13 +28,13 @@ test("create one incident ", async () => {
body: JSON.stringify({
status: "investigating",
date: "2023-11-08T21:03:13.000Z",
- title: "Test Incident",
+ title: "Test Status Report",
}),
});
expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: expect.any(Number),
status: "investigating",
- title: "Test Incident",
+ title: "Test Status Report",
});
});
diff --git a/apps/server/src/v1/incident.ts b/apps/server/src/v1/statusReport.ts
similarity index 50%
rename from apps/server/src/v1/incident.ts
rename to apps/server/src/v1/statusReport.ts
index ceca4336d..e03027924 100644
--- a/apps/server/src/v1/incident.ts
+++ b/apps/server/src/v1/statusReport.ts
@@ -2,16 +2,16 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { and, db, eq } from "@openstatus/db";
import {
- incident,
- incidentStatus,
- incidentUpdate,
+ statusReport,
+ statusReportStatus,
+ statusReportUpdate,
} from "@openstatus/db/src/schema";
-import { incidentUpdateSchema } from "./incidentUpdate";
import type { Variables } from "./index";
import { ErrorSchema } from "./shared";
+import { statusUpdateSchema } from "./statusReportUpdate";
-const incidentApi = new OpenAPIHono<{ Variables: Variables }>();
+const statusReportApi = new OpenAPIHono<{ Variables: Variables }>();
const ParamsSchema = z.object({
id: z
@@ -22,13 +22,13 @@ const ParamsSchema = z.object({
name: "id",
in: "path",
},
- description: "The id of the incident",
+ description: "The id of the status report",
example: "1",
}),
});
-const createIncidentUpdateSchema = z.object({
- status: z.enum(incidentStatus).openapi({
+const createStatusReportUpdateSchema = z.object({
+ status: z.enum(statusReportStatus).openapi({
description: "The status of the update",
}),
date: z.string().openapi({
@@ -39,43 +39,39 @@ const createIncidentUpdateSchema = z.object({
}),
});
-const incidentSchema = z.object({
+const statusSchema = z.object({
title: z.string().openapi({
example: "Documenso",
- description: "The title of the incident",
+ description: "The title of the status report",
}),
- status: z.enum(incidentStatus).openapi({
- description: "The current status of the incident",
+ status: z.enum(statusReportStatus).openapi({
+ description: "The current status of the report",
}),
});
-const incidentResultSchema = incidentSchema.extend({
- id: z.number().openapi({ description: "The id of the incident" }),
-});
-
-const incidentExtendedSchema = incidentSchema.extend({
- id: z.number().openapi({ description: "The id of the incident" }),
- incident_updates: z
+const statusReportExtendedSchema = statusSchema.extend({
+ id: z.number().openapi({ description: "The id of the status report" }),
+ status_report_updates: z
.array(z.number())
.openapi({
- description: "The ids of the incident updates",
+ description: "The ids of the status report updates",
})
.default([]),
});
const getAllRoute = createRoute({
method: "get",
- tags: ["incident"],
- description: "Get all incidents",
+ tags: ["status_report"],
+ description: "Get all status reports",
path: "/",
request: {},
responses: {
200: {
content: {
"application/json": {
- schema: z.array(incidentExtendedSchema),
+ schema: z.array(statusReportExtendedSchema),
},
},
- description: "Get all incidents",
+ description: "Get all status reports",
},
400: {
content: {
@@ -88,23 +84,25 @@ const getAllRoute = createRoute({
},
});
-incidentApi.openapi(getAllRoute, async (c) => {
+statusReportApi.openapi(getAllRoute, async (c) => {
const workspaceId = Number(c.get("workspaceId"));
- const _incidents = await db.query.incident.findMany({
+ const _statusReports = await db.query.statusReport.findMany({
with: {
- incidentUpdates: true,
+ statusReportUpdates: true,
},
- where: eq(incident.workspaceId, workspaceId),
+ where: eq(statusReport.workspaceId, workspaceId),
});
- if (!_incidents) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusReports) return c.jsonT({ code: 404, message: "Not Found" });
- const data = z.array(incidentExtendedSchema).parse(
- _incidents.map((incident) => ({
- ...incident,
- incident_updates: incident.incidentUpdates.map((incidentUpdate) => {
- return incidentUpdate.id;
- }),
+ const data = z.array(statusReportExtendedSchema).parse(
+ _statusReports.map((statusReport) => ({
+ ...statusReport,
+ status_report_updates: statusReport.statusReportUpdates.map(
+ (statusReportUpdate) => {
+ return statusReportUpdate.id;
+ },
+ ),
})),
);
@@ -113,8 +111,8 @@ incidentApi.openapi(getAllRoute, async (c) => {
const getRoute = createRoute({
method: "get",
- tags: ["incident"],
- description: "Get an incident",
+ tags: ["status_report"],
+ description: "Get an status report",
path: "/:id",
request: {
params: ParamsSchema,
@@ -123,10 +121,10 @@ const getRoute = createRoute({
200: {
content: {
"application/json": {
- schema: incidentExtendedSchema,
+ schema: statusReportExtendedSchema,
},
},
- description: "Get all incidents",
+ description: "Get all status reports",
},
400: {
content: {
@@ -139,26 +137,26 @@ const getRoute = createRoute({
},
});
-incidentApi.openapi(getRoute, async (c) => {
+statusReportApi.openapi(getRoute, async (c) => {
const workspaceId = Number(c.get("workspaceId"));
const { id } = c.req.valid("param");
- const incidentId = Number(id);
- const _incident = await db.query.incident.findFirst({
+ const statusUpdateId = Number(id);
+ const _statusUpdate = await db.query.statusReport.findFirst({
with: {
- incidentUpdates: true,
+ statusReportUpdates: true,
},
where: and(
- eq(incident.workspaceId, workspaceId),
- eq(incident.id, incidentId),
+ eq(statusReport.workspaceId, workspaceId),
+ eq(statusReport.id, statusUpdateId),
),
});
- if (!_incident) return c.jsonT({ code: 404, message: "Not Found" });
- const data = incidentExtendedSchema.parse({
- ..._incident,
- incident_updates: _incident.incidentUpdates.map(
- (incidentUpdate) => incidentUpdate.id,
+ if (!_statusUpdate) return c.jsonT({ code: 404, message: "Not Found" });
+ const data = statusReportExtendedSchema.parse({
+ ..._statusUpdate,
+ status_report_updates: _statusUpdate.statusReportUpdates.map(
+ (update) => update.id,
),
});
@@ -167,15 +165,15 @@ incidentApi.openapi(getRoute, async (c) => {
const postRoute = createRoute({
method: "post",
- tags: ["incident"],
- description: "Create an incident",
+ tags: ["status_report"],
+ description: "Create an status report",
path: "/",
request: {
body: {
- description: "The incident to create",
+ description: "The status report to create",
content: {
"application/json": {
- schema: incidentSchema,
+ schema: statusSchema,
},
},
},
@@ -184,10 +182,10 @@ const postRoute = createRoute({
200: {
content: {
"application/json": {
- schema: incidentExtendedSchema,
+ schema: statusReportExtendedSchema,
},
},
- description: "Incident created",
+ description: "Status report created",
},
400: {
content: {
@@ -200,12 +198,12 @@ const postRoute = createRoute({
},
});
-incidentApi.openapi(postRoute, async (c) => {
+statusReportApi.openapi(postRoute, async (c) => {
const input = c.req.valid("json");
const workspaceId = Number(c.get("workspaceId"));
- const _newIncident = await db
- .insert(incident)
+ const _newStatusReport = await db
+ .insert(statusReport)
.values({
...input,
workspaceId: workspaceId,
@@ -213,15 +211,15 @@ incidentApi.openapi(postRoute, async (c) => {
.returning()
.get();
- const data = incidentExtendedSchema.parse(_newIncident);
+ const data = statusReportExtendedSchema.parse(_newStatusReport);
return c.jsonT(data);
});
const deleteRoute = createRoute({
method: "delete",
- tags: ["incident"],
- description: "Delete an incident",
+ tags: ["status_report"],
+ description: "Delete an status report",
path: "/:id",
request: {
params: ParamsSchema,
@@ -237,7 +235,7 @@ const deleteRoute = createRoute({
}),
},
},
- description: "Incident deleted",
+ description: "Status report deleted",
},
400: {
content: {
@@ -250,38 +248,41 @@ const deleteRoute = createRoute({
},
});
-incidentApi.openapi(deleteRoute, async (c) => {
+statusReportApi.openapi(deleteRoute, async (c) => {
const workspaceId = Number(c.get("workspaceId"));
const { id } = c.req.valid("param");
- const incidentId = Number(id);
- const _incident = await db
+ const statusReportId = Number(id);
+ const _statusReport = await db
.select()
- .from(incident)
- .where(eq(incident.id, incidentId))
+ .from(statusReport)
+ .where(eq(statusReport.id, statusReportId))
.get();
- if (!_incident) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" });
- if (workspaceId !== _incident.workspaceId)
+ if (workspaceId !== _statusReport.workspaceId)
return c.jsonT({ code: 401, message: "Unauthorized" });
- await db.delete(incident).where(eq(incident.id, incidentId)).run();
+ await db
+ .delete(statusReport)
+ .where(eq(statusReport.id, statusReportId))
+ .run();
return c.jsonT({ message: "Deleted" });
});
const postRouteUpdate = createRoute({
method: "post",
- tags: ["incident"],
+ tags: ["status_report"],
path: "/:id/update",
- description: "Create an incident update",
+ description: "Create an status report update",
request: {
params: ParamsSchema,
body: {
- description: "the incident update",
+ description: "the status report update",
content: {
"application/json": {
- schema: createIncidentUpdateSchema,
+ schema: createStatusReportUpdateSchema,
},
},
},
@@ -290,10 +291,10 @@ const postRouteUpdate = createRoute({
200: {
content: {
"application/json": {
- schema: incidentUpdateSchema,
+ schema: statusUpdateSchema,
},
},
- description: "Incident updated",
+ description: "Status report updated",
},
400: {
content: {
@@ -306,37 +307,40 @@ const postRouteUpdate = createRoute({
},
});
-incidentApi.openapi(postRouteUpdate, async (c) => {
+statusReportApi.openapi(postRouteUpdate, async (c) => {
const input = c.req.valid("json");
const { id } = c.req.valid("param");
const workspaceId = Number(c.get("workspaceId"));
- const incidentId = Number(id);
- const _incident = await db
+ const statusReportId = Number(id);
+ const _statusReport = await db
.select()
- .from(incident)
+ .from(statusReport)
.where(
- and(eq(incident.id, incidentId), eq(incident.workspaceId, workspaceId)),
+ and(
+ eq(statusReport.id, statusReportId),
+ eq(statusReport.workspaceId, workspaceId),
+ ),
)
.get();
- if (!_incident) return c.jsonT({ code: 401, message: "Not authorized" });
+ if (!_statusReport) return c.jsonT({ code: 401, message: "Not authorized" });
- const _incidentUpdate = await db
- .insert(incidentUpdate)
+ const _statusReportUpdate = await db
+ .insert(statusReportUpdate)
.values({
...input,
date: new Date(input.date),
- incidentId: Number(id),
+ statusReportId: Number(id),
})
.returning()
.get();
- const data = incidentUpdateSchema.parse(_incidentUpdate);
+ const data = statusUpdateSchema.parse(_statusReportUpdate);
return c.jsonT({
...data,
});
});
-export { incidentApi };
+export { statusReportApi };
diff --git a/apps/server/src/v1/incidentUpdate.test.ts b/apps/server/src/v1/statusReportUpdate.test.ts
similarity index 71%
rename from apps/server/src/v1/incidentUpdate.test.ts
rename to apps/server/src/v1/statusReportUpdate.test.ts
index 74ff1eafe..45116c461 100644
--- a/apps/server/src/v1/incidentUpdate.test.ts
+++ b/apps/server/src/v1/statusReportUpdate.test.ts
@@ -2,8 +2,8 @@ import { expect, test } from "bun:test";
import { api } from ".";
-test("GET one incident update ", async () => {
- const res = await api.request("/incident_update/1", {
+test("GET one status report update ", async () => {
+ const res = await api.request("/status_report_update/1", {
headers: {
"x-openstatus-key": "1",
},
@@ -15,8 +15,8 @@ test("GET one incident update ", async () => {
});
});
-test("create one incident update ", async () => {
- const res = await api.request("/incident_update", {
+test("create one status report update ", async () => {
+ const res = await api.request("/status_report_update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
@@ -26,7 +26,7 @@ test("create one incident update ", async () => {
status: "investigating",
date: "2023-11-08T21:03:13.000Z",
message: "test",
- incident_id: 1,
+ status_report_id: 1,
}),
});
expect(res.status).toBe(200);
diff --git a/apps/server/src/v1/incidentUpdate.ts b/apps/server/src/v1/statusReportUpdate.ts
similarity index 61%
rename from apps/server/src/v1/incidentUpdate.ts
rename to apps/server/src/v1/statusReportUpdate.ts
index d56b52e85..00187275d 100644
--- a/apps/server/src/v1/incidentUpdate.ts
+++ b/apps/server/src/v1/statusReportUpdate.ts
@@ -2,15 +2,15 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { and, db, eq } from "@openstatus/db";
import {
- incident,
- incidentStatus,
- incidentUpdate,
+ statusReport,
+ statusReportStatus,
+ statusReportUpdate,
} from "@openstatus/db/src/schema";
import type { Variables } from ".";
import { ErrorSchema } from "./shared";
-const incidenUpdateApi = new OpenAPIHono<{ Variables: Variables }>();
+const statusReportUpdateApi = new OpenAPIHono<{ Variables: Variables }>();
const ParamsSelectSchema = z.object({
id: z
@@ -26,8 +26,8 @@ const ParamsSelectSchema = z.object({
}),
});
-export const incidentUpdateSchema = z.object({
- status: z.enum(incidentStatus).openapi({
+export const statusUpdateSchema = z.object({
+ status: z.enum(statusReportStatus).openapi({
description: "The status of the update",
}),
id: z.coerce.string().openapi({ description: "The id of the update" }),
@@ -41,11 +41,11 @@ export const incidentUpdateSchema = z.object({
}),
});
-const createIncidentUpdateSchema = z.object({
- incident_id: z.number().openapi({
- description: "The id of the incident",
+const createStatusReportUpdateSchema = z.object({
+ status_report_id: z.number().openapi({
+ description: "The id of the status report",
}),
- status: z.enum(incidentStatus).openapi({
+ status: z.enum(statusReportStatus).openapi({
description: "The status of the update",
}),
date: z.string().datetime().openapi({
@@ -57,7 +57,7 @@ const createIncidentUpdateSchema = z.object({
});
const getUpdateRoute = createRoute({
method: "get",
- tags: ["incident_update"],
+ tags: ["status_report_update"],
path: "/:id",
request: {
params: ParamsSelectSchema,
@@ -66,10 +66,10 @@ const getUpdateRoute = createRoute({
200: {
content: {
"application/json": {
- schema: incidentUpdateSchema,
+ schema: statusUpdateSchema,
},
},
- description: "Get all incidents",
+ description: "Get all status report updates",
},
400: {
content: {
@@ -82,46 +82,46 @@ const getUpdateRoute = createRoute({
},
});
-incidenUpdateApi.openapi(getUpdateRoute, async (c) => {
+statusReportUpdateApi.openapi(getUpdateRoute, async (c) => {
const workspaceId = Number(c.get("workspaceId"));
const { id } = c.req.valid("param");
const update = await db
.select()
- .from(incidentUpdate)
- .where(eq(incidentUpdate.id, Number(id)))
+ .from(statusReportUpdate)
+ .where(eq(statusReportUpdate.id, Number(id)))
.get();
if (!update) return c.jsonT({ code: 404, message: "Not Found" });
- const currentIncident = await db
+ const currentStatusReport = await db
.select()
- .from(incident)
+ .from(statusReport)
.where(
and(
- eq(incident.id, update.incidentId),
- eq(incident.workspaceId, workspaceId),
+ eq(statusReport.id, update.statusReportId),
+ eq(statusReport.workspaceId, workspaceId),
),
)
.get();
- if (!currentIncident)
+ if (!currentStatusReport)
return c.jsonT({ code: 401, message: "Not Authorized" });
- const data = incidentUpdateSchema.parse(update);
+ const data = statusUpdateSchema.parse(update);
return c.jsonT(data);
});
-const createIncidentUpdate = createRoute({
+const createStatusUpdate = createRoute({
method: "post",
- tags: ["incident_update"],
+ tags: ["status_report_update"],
path: "/",
request: {
body: {
- description: "the incident update",
+ description: "the status report update",
content: {
"application/json": {
- schema: createIncidentUpdateSchema,
+ schema: createStatusReportUpdateSchema,
},
},
},
@@ -130,10 +130,10 @@ const createIncidentUpdate = createRoute({
200: {
content: {
"application/json": {
- schema: incidentUpdateSchema,
+ schema: statusUpdateSchema,
},
},
- description: "Get all incidents",
+ description: "Get all status report updates",
},
400: {
content: {
@@ -146,35 +146,35 @@ const createIncidentUpdate = createRoute({
},
});
-incidenUpdateApi.openapi(createIncidentUpdate, async (c) => {
+statusReportUpdateApi.openapi(createStatusUpdate, async (c) => {
const workspaceId = Number(c.get("workspaceId"));
const input = c.req.valid("json");
- const currentIncident = await db
+ const _currentStatusReport = await db
.select()
- .from(incident)
+ .from(statusReport)
.where(
and(
- eq(incident.id, input.incident_id),
- eq(incident.workspaceId, workspaceId),
+ eq(statusReport.id, input.status_report_id),
+ eq(statusReport.workspaceId, workspaceId),
),
)
.get();
- if (!currentIncident)
+ if (!_currentStatusReport)
return c.jsonT({ code: 401, message: "Not Authorized" });
const res = await db
- .insert(incidentUpdate)
+ .insert(statusReportUpdate)
.values({
...input,
date: new Date(input.date),
- incidentId: input.incident_id,
+ statusReportId: input.status_report_id,
})
.returning()
.get();
- const data = incidentUpdateSchema.parse(res);
+ const data = statusUpdateSchema.parse(res);
return c.jsonT(data);
});
-export { incidenUpdateApi };
+export { statusReportUpdateApi };
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsx
index 467e0c4fe..7aba2ba96 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsx
@@ -6,7 +6,7 @@ import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
import { api } from "@/trpc/server";
-export default async function IncidentPage({
+export default async function IntegrationPage({
params,
}: {
params: { workspaceSlug: string };
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/action-button.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/action-button.tsx
similarity index 87%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/action-button.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/action-button.tsx
index 580ba0396..458d9e1e1 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/action-button.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/action-button.tsx
@@ -6,10 +6,7 @@ import { useRouter } from "next/navigation";
import { MoreVertical } from "lucide-react";
import type * as z from "zod";
-import {
- insertIncidentSchema,
- // insertIncidentUpdateSchema,
-} from "@openstatus/db/src/schema";
+import { insertStatusReportSchema } from "@openstatus/db/src/schema";
import {
AlertDialog,
AlertDialogAction,
@@ -31,7 +28,10 @@ import { LoadingAnimation } from "@/components/loading-animation";
import { useToastAction } from "@/hooks/use-toast-action";
import { api } from "@/trpc/client";
-const temporary = insertIncidentSchema.pick({ id: true, workspaceSlug: true });
+const temporary = insertStatusReportSchema.pick({
+ id: true,
+ workspaceSlug: true,
+});
type Schema = z.infer<typeof temporary>;
@@ -41,11 +41,11 @@ export function ActionButton(props: Schema) {
const [alertOpen, setAlertOpen] = React.useState(false);
const [isPending, startTransition] = React.useTransition();
- async function deleteIncident() {
+ async function deeteStatusReport() {
startTransition(async () => {
try {
if (!props.id) return;
- await api.incident.deleteIncident.mutate({ id: props.id });
+ await api.statusReport.deleteStatusReport.mutate({ id: props.id });
toast("deleted");
router.refresh();
setAlertOpen(false);
@@ -68,7 +68,7 @@ export function ActionButton(props: Schema) {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
- <Link href={`./incidents/edit?id=${props.id}`}>
+ <Link href={`./status-reports/edit?id=${props.id}`}>
<DropdownMenuItem>Edit</DropdownMenuItem>
</Link>
<AlertDialogTrigger asChild>
@@ -83,7 +83,7 @@ export function ActionButton(props: Schema) {
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
- incident.
+ status report.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -91,7 +91,7 @@ export function ActionButton(props: Schema) {
<AlertDialogAction
onClick={(e) => {
e.preventDefault();
- deleteIncident();
+ deeteStatusReport();
}}
disabled={isPending}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/delete-incident-update.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update.tsx
similarity index 92%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/delete-incident-update.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update.tsx
index 9450e7d9a..3107b36b1 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/delete-incident-update.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update.tsx
@@ -21,7 +21,7 @@ import { LoadingAnimation } from "@/components/loading-animation";
import { useToastAction } from "@/hooks/use-toast-action";
import { api } from "@/trpc/client";
-export function DeleteIncidentUpdateButtonIcon({ id }: { id: number }) {
+export function DeleteStatusReportUpdateButtonIcon({ id }: { id: number }) {
const router = useRouter();
const { toast } = useToastAction();
const [alertOpen, setAlertOpen] = React.useState(false);
@@ -30,7 +30,7 @@ export function DeleteIncidentUpdateButtonIcon({ id }: { id: number }) {
async function onDelete() {
startTransition(async () => {
try {
- await api.incident.deleteIncidentUpdate.mutate({ id });
+ await api.statusReport.deleteStatusReportUpdate.mutate({ id });
toast("deleted");
router.refresh();
setAlertOpen(false);
@@ -56,7 +56,7 @@ export function DeleteIncidentUpdateButtonIcon({ id }: { id: number }) {
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
- monitor.
+ status report update.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/empty-state.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/empty-state.tsx
similarity index 69%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/empty-state.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/empty-state.tsx
index 2c09dcdaf..75fa4cafc 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/_components/empty-state.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/empty-state.tsx
@@ -8,11 +8,11 @@ export function EmptyState() {
return (
<DefaultEmptyState
icon="siren"
- title="No incidents"
- description="Create your first incident"
+ title="No status reports"
+ description="Create your first status report"
action={
<Button asChild>
- <Link href="./incidents/edit">Create</Link>
+ <Link href="./status-reports/edit">Create</Link>
</Button>
}
/>
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/loading.tsx
similarity index 100%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/loading.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/loading.tsx
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/page.tsx
similarity index 67%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/page.tsx
index 416baa071..4cf02abe2 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/edit/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/page.tsx
@@ -2,7 +2,7 @@ import { notFound } from "next/navigation";
import * as z from "zod";
import { Header } from "@/components/dashboard/header";
-import { IncidentForm } from "@/components/forms/incident-form";
+import { StatusReportForm } from "@/components/forms/status-report-form";
import { api } from "@/trpc/server";
/**
@@ -27,8 +27,8 @@ export default async function EditPage({
const { id } = search.data;
- const incident = id
- ? await api.incident.getIncidentById.query({
+ const statusUpdate = id
+ ? await api.statusReport.getStatusReportById.query({
id,
})
: undefined;
@@ -39,22 +39,27 @@ export default async function EditPage({
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
- <Header title="Incident" description="Upsert your incident." />
+ <Header
+ title="Status Report"
+ description="Create a public report for your incident"
+ />
<div className="col-span-full">
- <IncidentForm
+ <StatusReportForm
monitors={monitors}
pages={pages}
defaultValues={
- incident
+ statusUpdate
? // TODO: we should move the mapping to the trpc layer
// so we don't have to do this in the UI
- // it should be something like defaultValues={incident}
+ // it should be something like defaultValues={statusReport}
{
- ...incident,
- monitors: incident?.monitorsToIncidents.map(
+ ...statusUpdate,
+ monitors: statusUpdate?.monitorsToStatusReports.map(
({ monitorId }) => monitorId,
),
- pages: incident?.pagesToIncidents.map(({ pageId }) => pageId),
+ pages: statusUpdate?.pagesToStatusReports.map(
+ ({ pageId }) => pageId,
+ ),
message: "",
}
: undefined
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/loading.tsx
similarity index 100%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/loading.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/loading.tsx
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/page.tsx
similarity index 72%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/page.tsx
index 2bd6b1e00..1bbce27a0 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/page.tsx
@@ -8,63 +8,63 @@ import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
import { HelpCallout } from "@/components/dashboard/help-callout";
import { Icons } from "@/components/icons";
-import { AffectedMonitors } from "@/components/incidents/affected-monitors";
-import { Events } from "@/components/incidents/events";
-import { StatusBadge } from "@/components/incidents/status-badge";
+import { AffectedMonitors } from "@/components/status-update/affected-monitors";
+import { Events } from "@/components/status-update/events";
+import { StatusBadge } from "@/components/status-update/status-badge";
import { statusDict } from "@/data/incidents-dictionary";
import { api } from "@/trpc/server";
import { ActionButton } from "./_components/action-button";
import { EmptyState } from "./_components/empty-state";
-export default async function IncidentPage({
+export default async function StatusReportsPage({
params,
}: {
params: { workspaceSlug: string };
}) {
- const incidents = await api.incident.getIncidentByWorkspace.query();
+ const reports = await api.statusReport.getStatusReportByWorkspace.query();
return (
<div className="grid min-h-full grid-cols-1 grid-rows-[auto,1fr,auto] gap-6 md:grid-cols-1 md:gap-8">
<Header
- title="Incidents"
- description="Overview of all your incidents."
+ title="Status Reports"
+ description="Overview of all your status reports and updates."
actions={
<Button asChild>
- <Link href="./incidents/edit">Create</Link>
+ <Link href="./status-reports/edit">Create</Link>
</Button>
}
/>
- {Boolean(incidents?.length) ? (
+ {Boolean(reports?.length) ? (
<div className="col-span-full">
<ul role="list" className="grid gap-4 sm:col-span-6">
- {incidents?.map((incident, i) => {
+ {reports?.map((report, i) => {
const { label, icon } =
- statusDict[incident.status as keyof typeof statusDict];
- const monitors = incident.monitorsToIncidents.map(
+ statusDict[report.status as keyof typeof statusDict];
+ const monitors = report.monitorsToStatusReports.map(
({ monitor }) => monitor,
);
return (
<li key={i} className="grid gap-2">
<time className="text-muted-foreground pl-3 text-xs">
- {formatDistance(new Date(incident.createdAt!), new Date(), {
+ {formatDistance(new Date(report.createdAt!), new Date(), {
addSuffix: true,
})}
</time>
<Container
title={
<span className="flex flex-wrap gap-2">
- {incident.title}
- <StatusBadge status={incident.status} />
+ {report.title}
+ <StatusBadge status={report.status} />
</span>
}
actions={[
<Button key="status-button" variant="outline" size="sm">
<Link
- href={`./incidents/update/edit?incidentId=${incident.id}`}
+ href={`./status-reports/update/edit?id=${report.id}`}
>
New Update
</Link>
</Button>,
- <ActionButton key="action-button" id={incident.id} />,
+ <ActionButton key="action-button" id={report.id} />,
]}
>
<div className="grid gap-4">
@@ -82,7 +82,7 @@ export default async function IncidentPage({
</p>
{/* Make it ordered by desc and make it toggable if you want the whole history! */}
<Events
- incidentUpdates={incident.incidentUpdates}
+ statusReportUpdates={report.statusReportUpdates}
editable
/>
</div>
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/update/edit/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/loading.tsx
similarity index 100%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/update/edit/loading.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/loading.tsx
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/update/edit/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/page.tsx
similarity index 58%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/update/edit/page.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/page.tsx
index 0690d7833..aebe1d651 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/incidents/update/edit/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/page.tsx
@@ -2,15 +2,15 @@ import { notFound } from "next/navigation";
import * as z from "zod";
import { Header } from "@/components/dashboard/header";
-import { IncidentUpdateForm } from "@/components/forms/incident-update-form";
+import { StatusReportUpdateForm } from "@/components/forms/status-report-update-form";
import { api } from "@/trpc/server";
/**
* allowed URL search params
*/
const searchParamsSchema = z.object({
- id: z.coerce.number().optional(),
- incidentId: z.coerce.number(),
+ id: z.coerce.number(),
+ statusUpdate: z.coerce.number().optional(),
});
export default async function EditPage({
@@ -26,24 +26,24 @@ export default async function EditPage({
return notFound();
}
- const { id, incidentId } = search.data;
+ const { id, statusUpdate } = search.data;
- const incidentUpdate = id
- ? await api.incident.getIncidentUpdateById.query({
- id,
+ const data = statusUpdate
+ ? await api.statusReport.getStatusReportUpdateById.query({
+ id: statusUpdate,
})
: undefined;
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
<Header
- title="Incident Update"
- description="Upsert your incident update."
+ title="Status Report Update"
+ description="Create a public update for your incident"
/>
<div className="col-span-full">
- <IncidentUpdateForm
- incidentId={incidentId}
- defaultValues={incidentUpdate || undefined}
+ <StatusReportUpdateForm
+ statusReportId={id}
+ defaultValues={data || undefined}
/>
</div>
</div>
diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx
index 42f333e93..37e23872f 100644
--- a/apps/web/src/app/page.tsx
+++ b/apps/web/src/app/page.tsx
@@ -19,6 +19,7 @@ export default async function Page() {
<Example />
<Cards {...cardConfig.monitors} />
<Stats />
+ {/* TODO: rename to `reports` */}
<Cards {...cardConfig.incidents} />
<Partners />
<Cards {...cardConfig.pages} />
diff --git a/apps/web/src/app/status-page/[domain]/incidents/page.tsx b/apps/web/src/app/status-page/[domain]/incidents/page.tsx
index 962095581..8d48273de 100644
--- a/apps/web/src/app/status-page/[domain]/incidents/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/incidents/page.tsx
@@ -28,7 +28,7 @@ export default async function Page({ params }: Props) {
description={page.description}
className="text-left"
/>
- <IncidentList incidents={page.incidents} monitors={page.monitors} />
+ <IncidentList incidents={page.statusReports} monitors={page.monitors} />
</div>
);
}
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index c636bfb4a..e96bdb406 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -36,7 +36,7 @@ export default async function Page({ params }: Props) {
}
const isEmptyState = !(
- Boolean(page.monitors.length) || Boolean(page.incidents.length)
+ Boolean(page.monitors.length) || Boolean(page.statusReports.length)
);
return (
@@ -59,10 +59,14 @@ export default async function Page({ params }: Props) {
/>
) : (
<>
- <StatusCheck incidents={page.incidents} monitors={page.monitors} />
+ <StatusCheck
+ statusReports={page.statusReports}
+ monitors={page.monitors}
+ />
<MonitorList monitors={page.monitors} />
+ {/* TODO: rename to StatusReportList */}
<IncidentList
- incidents={page.incidents}
+ incidents={page.statusReports}
monitors={page.monitors}
context="latest"
/>
diff --git a/apps/web/src/components/forms/incident-form.tsx b/apps/web/src/components/forms/status-report-form.tsx
similarity index 93%
rename from apps/web/src/components/forms/incident-form.tsx
rename to apps/web/src/components/forms/status-report-form.tsx
index 48f84a75b..04644dff4 100644
--- a/apps/web/src/components/forms/incident-form.tsx
+++ b/apps/web/src/components/forms/status-report-form.tsx
@@ -5,11 +5,15 @@ import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
-import type { InsertIncident, Monitor, Page } from "@openstatus/db/src/schema";
import {
- incidentStatus,
- incidentStatusSchema,
- insertIncidentSchema,
+ insertStatusReportSchema,
+ statusReportStatus,
+ statusReportStatusSchema,
+} from "@openstatus/db/src/schema";
+import type {
+ InsertStatusReport,
+ Monitor,
+ Page,
} from "@openstatus/db/src/schema";
import {
Accordion,
@@ -45,14 +49,14 @@ import { cn } from "@/lib/utils";
import { api } from "@/trpc/client";
interface Props {
- defaultValues?: InsertIncident;
+ defaultValues?: InsertStatusReport;
monitors?: Monitor[];
pages?: Page[];
}
-export function IncidentForm({ defaultValues, monitors, pages }: Props) {
- const form = useForm<InsertIncident>({
- resolver: zodResolver(insertIncidentSchema),
+export function StatusReportForm({ defaultValues, monitors, pages }: Props) {
+ const form = useForm<InsertStatusReport>({
+ resolver: zodResolver(insertStatusReportSchema),
defaultValues: defaultValues
? {
id: defaultValues.id,
@@ -73,26 +77,27 @@ export function IncidentForm({ defaultValues, monitors, pages }: Props) {
const [isPending, startTransition] = React.useTransition();
const { toast } = useToastAction();
- const onSubmit = ({ ...props }: InsertIncident) => {
+ const onSubmit = ({ ...props }: InsertStatusReport) => {
startTransition(async () => {
try {
if (defaultValues) {
- await api.incident.updateIncident.mutate({ ...props });
+ await api.statusReport.updateStatusReport.mutate({ ...props });
} else {
- // or use createIncident to create automaticaaly an IncidentUpdate?
const { message, date, status, ...rest } = props;
- const incident = await api.incident.createIncident.mutate({
- status,
- message,
- ...rest,
- });
+ const statusReport = await api.statusReport.createStatusReport.mutate(
+ {
+ status,
+ message,
+ ...rest,
+ },
+ );
// include update on creation
- if (incident?.id) {
- await api.incident.createIncidentUpdate.mutate({
+ if (statusReport?.id) {
+ await api.statusReport.createStatusReportUpdate.mutate({
message,
date,
status,
- incidentId: incident.id,
+ statusReportId: statusReport.id,
});
}
}
@@ -104,7 +109,6 @@ export function IncidentForm({ defaultValues, monitors, pages }: Props) {
});
};
- console.log(form.formState.errors);
return (
<Form {...form}>
<form
@@ -146,12 +150,12 @@ export function IncidentForm({ defaultValues, monitors, pages }: Props) {
<FormMessage />
<RadioGroup
onValueChange={(value) =>
- field.onChange(incidentStatusSchema.parse(value))
+ field.onChange(statusReportStatusSchema.parse(value))
} // value is a string
defaultValue={field.value}
className="grid grid-cols-2 gap-4 sm:grid-cols-4"
>
- {incidentStatus.map((status) => {
+ {statusReportStatus.map((status) => {
const { value, label, icon } = statusDict[status];
const Icon = Icons[icon];
return (
@@ -317,7 +321,7 @@ export function IncidentForm({ defaultValues, monitors, pages }: Props) {
<div className="grid gap-4 sm:grid-cols-3">
<div className="my-1.5 flex flex-col gap-2">
<p className="text-sm font-semibold leading-none">
- Incident Update
+ Status Update
</p>
<p className="text-muted-foreground text-sm">
What is actually going wrong?
diff --git a/apps/web/src/components/forms/incident-update-form.tsx b/apps/web/src/components/forms/status-report-update-form.tsx
similarity index 88%
rename from apps/web/src/components/forms/incident-update-form.tsx
rename to apps/web/src/components/forms/status-report-update-form.tsx
index d9d843271..f8a8dd280 100644
--- a/apps/web/src/components/forms/incident-update-form.tsx
+++ b/apps/web/src/components/forms/status-report-update-form.tsx
@@ -5,11 +5,11 @@ import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
-import type { InsertIncidentUpdate } from "@openstatus/db/src/schema";
+import type { InsertStatusReportUpdate } from "@openstatus/db/src/schema";
import {
- incidentStatus,
- incidentStatusSchema,
- insertIncidentUpdateSchema,
+ insertStatusReportUpdateSchema,
+ statusReportStatus,
+ statusReportStatusSchema,
} from "@openstatus/db/src/schema";
import {
Button,
@@ -38,32 +38,35 @@ import { useToastAction } from "@/hooks/use-toast-action";
import { api } from "@/trpc/client";
interface Props {
- defaultValues?: InsertIncidentUpdate;
- incidentId: number;
+ defaultValues?: InsertStatusReportUpdate;
+ statusReportId: number;
}
-export function IncidentUpdateForm({ defaultValues, incidentId }: Props) {
- const form = useForm<InsertIncidentUpdate>({
- resolver: zodResolver(insertIncidentUpdateSchema),
+export function StatusReportUpdateForm({
+ defaultValues,
+ statusReportId,
+}: Props) {
+ const form = useForm<InsertStatusReportUpdate>({
+ resolver: zodResolver(insertStatusReportUpdateSchema),
defaultValues: {
id: defaultValues?.id || 0,
status: defaultValues?.status || "investigating",
message: defaultValues?.message,
date: defaultValues?.date || new Date(),
- incidentId,
+ statusReportId,
},
});
const router = useRouter();
const [isPending, startTransition] = React.useTransition();
const { toast } = useToastAction();
- const onSubmit = ({ ...props }: InsertIncidentUpdate) => {
+ const onSubmit = ({ ...props }: InsertStatusReportUpdate) => {
startTransition(async () => {
try {
if (defaultValues) {
- await api.incident.updateIncidentUpdate.mutate({ ...props });
+ await api.statusReport.updateStatusReportUpdate.mutate({ ...props });
} else {
- await api.incident.createIncidentUpdate.mutate({ ...props });
+ await api.statusReport.createStatusReportUpdate.mutate({ ...props });
}
toast("saved");
router.refresh();
@@ -100,12 +103,12 @@ export function IncidentUpdateForm({ defaultValues, incidentId }: Props) {
<FormMessage />
<RadioGroup
onValueChange={(value) =>
- field.onChange(incidentStatusSchema.parse(value))
+ field.onChange(statusReportStatusSchema.parse(value))
} // value is a string
defaultValue={field.value}
className="grid grid-cols-2 gap-4 sm:grid-cols-4"
>
- {incidentStatus.map((status) => {
+ {statusReportStatus.map((status) => {
const { value, label, icon } = statusDict[status];
const Icon = Icons[icon];
return (
diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsx
index d7af584a4..2a805f173 100644
--- a/apps/web/src/components/icons.tsx
+++ b/apps/web/src/components/icons.tsx
@@ -13,6 +13,7 @@ import {
Laptop,
LayoutDashboard,
Link,
+ Megaphone,
MessageCircle,
Minus,
Moon,
@@ -66,6 +67,7 @@ export const Icons = {
bell: Bell,
zap: Zap,
"alert-triangle": AlertTriangle,
+ megaphone: Megaphone,
minus: Minus,
sun: SunMedium,
moon: Moon,
diff --git a/apps/web/src/components/status-page/incident-list.tsx b/apps/web/src/components/status-page/incident-list.tsx
index 0dd0db424..7e15c288c 100644
--- a/apps/web/src/components/status-page/incident-list.tsx
+++ b/apps/web/src/components/status-page/incident-list.tsx
@@ -1,14 +1,14 @@
import type { z } from "zod";
import type {
- selectIncidentsPageSchema,
selectPublicMonitorSchema,
+ selectStatusReportPageSchema,
} from "@openstatus/db/src/schema";
import { notEmpty } from "@/lib/utils";
-import { AffectedMonitors } from "../incidents/affected-monitors";
-import { Events } from "../incidents/events";
-import { StatusBadge } from "../incidents/status-badge";
+import { AffectedMonitors } from "../status-update/affected-monitors";
+import { Events } from "../status-update/events";
+import { StatusBadge } from "../status-update/status-badge";
// TODO: change layout - it is too packed with data rn
@@ -17,7 +17,7 @@ export const IncidentList = ({
monitors,
context = "all",
}: {
- incidents: z.infer<typeof selectIncidentsPageSchema>;
+ incidents: z.infer<typeof selectStatusReportPageSchema>;
monitors: z.infer<typeof selectPublicMonitorSchema>[];
context?: "all" | "latest"; // latest 7 days
}) => {
@@ -25,7 +25,7 @@ export const IncidentList = ({
function getLastWeeksIncidents() {
return incidents.filter((incident) => {
- return incident.incidentUpdates.some(
+ return incident.statusReportUpdates.some(
(update) => update.date.getTime() > lastWeek,
);
});
@@ -45,7 +45,7 @@ export const IncidentList = ({
{context === "all" ? "All incidents" : "Latest incidents"}
</h2>
{_incidents.map((incident) => {
- const affectedMonitors = incident.monitorsToIncidents
+ const affectedMonitors = incident.monitorsToStatusReport
.map(({ monitorId }) => {
const monitor = monitors.find(({ id }) => monitorId === id);
return monitor || undefined;
@@ -63,7 +63,7 @@ export const IncidentList = ({
Affected Monitors
</p>
<AffectedMonitors
- monitors={incident.monitorsToIncidents
+ monitors={incident.monitorsToStatusReport
.map(({ monitorId }) => {
const monitor = monitors.find(
({ id }) => monitorId === id,
@@ -78,7 +78,7 @@ export const IncidentList = ({
<p className="text-muted-foreground mb-2 text-xs">
Latest Updates
</p>
- <Events incidentUpdates={incident.incidentUpdates} />
+ <Events statusReportUpdates={incident.statusReportUpdates} />
</div>
</div>
);
diff --git a/apps/web/src/components/status-page/status-check.tsx b/apps/web/src/components/status-page/status-check.tsx
index 050a37ccc..3807d384e 100644
--- a/apps/web/src/components/status-page/status-check.tsx
+++ b/apps/web/src/components/status-page/status-check.tsx
@@ -2,8 +2,8 @@ import { cva } from "class-variance-authority";
import type { z } from "zod";
import type {
- selectIncidentsPageSchema,
selectPublicMonitorSchema,
+ selectStatusReportPageSchema,
} from "@openstatus/db/src/schema";
import { getResponseListData } from "@/lib/tb";
@@ -28,13 +28,13 @@ const check = cva("border-border rounded-full border p-2", {
});
export async function StatusCheck({
- incidents,
+ statusReports,
monitors,
}: {
- incidents: z.infer<typeof selectIncidentsPageSchema>;
+ statusReports: z.infer<typeof selectStatusReportPageSchema>;
monitors: z.infer<typeof selectPublicMonitorSchema>[];
}) {
- const isIncident = incidents.some(
+ const isIncident = statusReports.some(
(incident) => !["monitoring", "resolved"].includes(incident.status),
);
diff --git a/apps/web/src/components/incidents/affected-monitors.tsx b/apps/web/src/components/status-update/affected-monitors.tsx
similarity index 100%
rename from apps/web/src/components/incidents/affected-monitors.tsx
rename to apps/web/src/components/status-update/affected-monitors.tsx
diff --git a/apps/web/src/components/incidents/events.tsx b/apps/web/src/components/status-update/events.tsx
similarity index 85%
rename from apps/web/src/components/incidents/events.tsx
rename to apps/web/src/components/status-update/events.tsx
index fde4a2ac8..44aa8339b 100644
--- a/apps/web/src/components/incidents/events.tsx
+++ b/apps/web/src/components/status-update/events.tsx
@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
import { format, formatDistance } from "date-fns";
import type * as z from "zod";
-import type { selectIncidentUpdateSchema } from "@openstatus/db/src/schema";
+import type { selectStatusReportUpdateSchema } from "@openstatus/db/src/schema";
import {
Button,
Tooltip,
@@ -14,26 +14,26 @@ import {
TooltipTrigger,
} from "@openstatus/ui";
+import { DeleteStatusReportUpdateButtonIcon } from "@/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update";
import { Icons } from "@/components/icons";
import { statusDict } from "@/data/incidents-dictionary";
import { useProcessor } from "@/hooks/use-preprocessor";
import { cn } from "@/lib/utils";
-import { DeleteIncidentUpdateButtonIcon } from "../../app/app/(dashboard)/[workspaceSlug]/incidents/_components/delete-incident-update";
-type IncidentUpdateProps = z.infer<typeof selectIncidentUpdateSchema>;
+type StatusReportUpdateProps = z.infer<typeof selectStatusReportUpdateSchema>;
export function Events({
- incidentUpdates,
+ statusReportUpdates,
editable = false,
}: {
- incidentUpdates: IncidentUpdateProps[];
+ statusReportUpdates: StatusReportUpdateProps[];
editable?: boolean;
}) {
const [open, toggle] = React.useReducer((open) => !open, false);
const router = useRouter();
// TODO: make it simpler..
- const sortedArray = incidentUpdates.sort((a, b) => {
+ const sortedArray = statusReportUpdates.sort((a, b) => {
const orderA = statusDict[a.status].order;
const orderB = statusDict[b.status].order;
return orderB - orderA;
@@ -75,13 +75,13 @@ export function Events({
className="h-7 w-7 p-0"
onClick={() => {
router.push(
- `./incidents/update/edit?incidentId=${update.incidentId}&id=${update.id}`,
+ `./status-reports/update/edit?id=${update.statusReportId}&statusUpdate=${update.id}`,
);
}}
>
<Icons.pencil className="h-4 w-4" />
</Button>
- <DeleteIncidentUpdateButtonIcon id={update.id} />
+ <DeleteStatusReportUpdateButtonIcon id={update.id} />
</div>
) : undefined}
<div className="flex items-center justify-between gap-4">
@@ -106,7 +106,7 @@ export function Events({
);
})}
- {incidentUpdates.length > 1 ? (
+ {statusReportUpdates.length > 1 ? (
<div className="text-center">
<Button variant="ghost" onClick={toggle}>
{open ? "Close" : "More"}
diff --git a/apps/web/src/components/incidents/status-badge.tsx b/apps/web/src/components/status-update/status-badge.tsx
similarity index 100%
rename from apps/web/src/components/incidents/status-badge.tsx
rename to apps/web/src/components/status-update/status-badge.tsx
diff --git a/apps/web/src/config/features.ts b/apps/web/src/config/features.ts
index 8d77b47b4..d2705f4e8 100644
--- a/apps/web/src/config/features.ts
+++ b/apps/web/src/config/features.ts
@@ -85,8 +85,8 @@ export const cardConfig = {
},
{
icon: "message-circle",
- catchline: "Inform.",
- description: "Keep your teams and users updated with incident updates.",
+ catchline: "Status Reports.",
+ description: "Keep your teams and users updated with status updates.",
},
{
icon: "zap",
diff --git a/apps/web/src/config/pages.ts b/apps/web/src/config/pages.ts
index c2b33b086..b2424e20b 100644
--- a/apps/web/src/config/pages.ts
+++ b/apps/web/src/config/pages.ts
@@ -22,18 +22,18 @@ export const pagesConfig: Page[] = [
href: "/status-pages",
icon: "panel-top",
},
+ {
+ title: "Status Reports",
+ description: "War room where you handle the incidents.",
+ href: "/status-reports",
+ icon: "megaphone",
+ },
{
title: "Notifications",
description: "Where you can see all the notifications.",
href: "/notifications",
icon: "bell",
},
- {
- title: "Incidents",
- description: "War room where you handle the incidents.",
- href: "/incidents",
- icon: "siren",
- },
// {
// title: "Integrations",
// description: "Where you can see all the integrations.",
diff --git a/fly.toml b/fly.toml
deleted file mode 100644
index 37c323b6c..000000000
--- a/fly.toml
+++ /dev/null
@@ -1,18 +0,0 @@
-# fly.toml app configuration file generated for openstatus-api on 2023-09-13T17:29:05+02:00
-#
-# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
-#
-
-app = "openstatus-api"
-primary_region = "ams"
-
-[build]
- dockerfile = "apps/server/Dockerfile"
-
-[http_service]
- internal_port = 3000
- force_https = true
- auto_stop_machines = true
- auto_start_machines = true
- min_machines_running = 0
- processes = ["app"]
diff --git a/packages/api/src/analytics.ts b/packages/api/src/analytics.ts
index 974f00330..ae2807276 100644
--- a/packages/api/src/analytics.ts
+++ b/packages/api/src/analytics.ts
@@ -44,4 +44,4 @@ export async function trackNewNotification(
});
}
-export async function trackNewIncident() {}
+export async function trackNewStatusReport() {}
diff --git a/packages/api/src/edge.ts b/packages/api/src/edge.ts
index f8e9129c5..99943b122 100644
--- a/packages/api/src/edge.ts
+++ b/packages/api/src/edge.ts
@@ -1,9 +1,9 @@
import { domainRouter } from "./router/domain";
-import { incidentRouter } from "./router/incident";
import { integrationRouter } from "./router/integration";
import { monitorRouter } from "./router/monitor";
import { notificationRouter } from "./router/notification";
import { pageRouter } from "./router/page";
+import { statusReportRouter } from "./router/statusReport";
import { userRouter } from "./router/user";
import { workspaceRouter } from "./router/workspace";
import { createTRPCRouter } from "./trpc";
@@ -13,7 +13,7 @@ export const edgeRouter = createTRPCRouter({
workspace: workspaceRouter,
monitor: monitorRouter,
page: pageRouter,
- incident: incidentRouter,
+ statusReport: statusReportRouter,
domain: domainRouter,
integration: integrationRouter,
user: userRouter,
diff --git a/packages/api/src/router/incident.ts b/packages/api/src/router/incident.ts
deleted file mode 100644
index 1898af726..000000000
--- a/packages/api/src/router/incident.ts
+++ /dev/null
@@ -1,317 +0,0 @@
-import { z } from "zod";
-
-import { and, eq, inArray } from "@openstatus/db";
-import {
- incident,
- incidentStatusSchema,
- incidentUpdate,
- insertIncidentSchema,
- insertIncidentUpdateSchema,
- monitorsToIncidents,
- pagesToIncidents,
- selectIncidentSchema,
- selectIncidentUpdateSchema,
- selectMonitorSchema,
-} from "@openstatus/db/src/schema";
-
-import { createTRPCRouter, protectedProcedure } from "../trpc";
-
-export const incidentRouter = createTRPCRouter({
- createIncident: protectedProcedure
- .input(insertIncidentSchema)
- .mutation(async (opts) => {
- const { id, monitors, pages, date, message, ...incidentInput } =
- opts.input;
-
- const newIncident = await opts.ctx.db
- .insert(incident)
- .values({
- workspaceId: opts.ctx.workspace.id,
- ...incidentInput,
- })
- .returning()
- .get();
-
- if (Boolean(monitors.length)) {
- await opts.ctx.db
- .insert(monitorsToIncidents)
- .values(
- monitors.map((monitor) => ({
- monitorId: monitor,
- incidentId: newIncident.id,
- })),
- )
- .returning()
- .get();
- }
-
- if (Boolean(pages.length)) {
- await opts.ctx.db
- .insert(pagesToIncidents)
- .values(
- pages.map((page) => ({
- pageId: page,
- incidentId: newIncident.id,
- })),
- )
- .returning()
- .get();
- }
-
- return newIncident;
- }),
-
- createIncidentUpdate: protectedProcedure
- .input(insertIncidentUpdateSchema)
- .mutation(async (opts) => {
- // update parent incident with latest status
- await opts.ctx.db
- .update(incident)
- .set({ status: opts.input.status, updatedAt: new Date() })
- .where(
- and(
- eq(incident.id, opts.input.incidentId),
- eq(incident.workspaceId, opts.ctx.workspace.id),
- ),
- )
- .returning()
- .get();
-
- const { id, ...incidentUpdateInput } = opts.input;
- return await opts.ctx.db
- .insert(incidentUpdate)
- .values(incidentUpdateInput)
- .returning()
- .get();
- }),
-
- updateIncident: protectedProcedure
- .input(insertIncidentSchema)
- .mutation(async (opts) => {
- const { monitors, pages, ...incidentInput } = opts.input;
-
- if (!incidentInput.id) return;
-
- const { title, status } = incidentInput;
-
- const currentIncident = await opts.ctx.db
- .update(incident)
- .set({ title, status, updatedAt: new Date() })
- .where(
- and(
- eq(incident.id, incidentInput.id),
- eq(incident.workspaceId, opts.ctx.workspace.id),
- ),
- )
- .returning()
- .get();
-
- const currentMonitorToIncidents = await opts.ctx.db
- .select()
- .from(monitorsToIncidents)
- .where(eq(monitorsToIncidents.incidentId, currentIncident.id))
- .all();
-
- const addedMonitors = monitors.filter(
- (x) =>
- !currentMonitorToIncidents
- .map(({ monitorId }) => monitorId)
- .includes(x),
- );
-
- if (Boolean(addedMonitors.length)) {
- const values = addedMonitors.map((monitorId) => ({
- monitorId: monitorId,
- incidentId: currentIncident.id,
- }));
-
- await opts.ctx.db.insert(monitorsToIncidents).values(values).run();
- }
-
- const removedMonitors = currentMonitorToIncidents
- .map(({ monitorId }) => monitorId)
- .filter((x) => !monitors?.includes(x));
-
- if (Boolean(removedMonitors.length)) {
- await opts.ctx.db
- .delete(monitorsToIncidents)
- .where(
- and(
- eq(monitorsToIncidents.incidentId, currentIncident.id),
- inArray(monitorsToIncidents.monitorId, removedMonitors),
- ),
- )
- .run();
- }
-
- const currentPagesToIncidents = await opts.ctx.db
- .select()
- .from(pagesToIncidents)
- .where(eq(pagesToIncidents.incidentId, currentIncident.id))
- .all();
-
- const addedPages = pages?.filter(
- (x) =>
- !currentPagesToIncidents.map(({ pageId }) => pageId)?.includes(x),
- );
-
- if (Boolean(addedPages.length)) {
- const values = addedPages.map((pageId) => ({
- pageId,
- incidentId: currentIncident.id,
- }));
-
- await opts.ctx.db.insert(pagesToIncidents).values(values).run();
- }
-
- const removedPages = currentPagesToIncidents
- .map(({ pageId }) => pageId)
- .filter((x) => !pages?.includes(x));
-
- if (Boolean(removedPages.length)) {
- await opts.ctx.db
- .delete(pagesToIncidents)
- .where(
- and(
- eq(pagesToIncidents.incidentId, currentIncident.id),
- inArray(pagesToIncidents.pageId, removedPages),
- ),
- )
- .run();
- }
-
- return currentIncident;
- }),
-
- updateIncidentUpdate: protectedProcedure
- .input(insertIncidentUpdateSchema)
- .mutation(async (opts) => {
- const incidentUpdateInput = opts.input;
-
- if (!incidentUpdateInput.id) return;
-
- const currentIncident = await opts.ctx.db
- .update(incidentUpdate)
- .set(incidentUpdateInput)
- .where(eq(incidentUpdate.id, incidentUpdateInput.id))
- .returning()
- .get();
-
- return currentIncident;
- }),
-
- deleteIncident: protectedProcedure
- .input(z.object({ id: z.number() }))
- .mutation(async (opts) => {
- const incidentToDelete = await opts.ctx.db
- .select()
- .from(incident)
- .where(
- and(
- eq(incident.id, opts.input.id),
- eq(incident.workspaceId, opts.ctx.workspace.id),
- ),
- )
- .get();
- if (!incidentToDelete) return;
-
- await opts.ctx.db
- .delete(incident)
- .where(eq(incident.id, incidentToDelete.id))
- .run();
- }),
-
- deleteIncidentUpdate: protectedProcedure
- .input(z.object({ id: z.number() }))
- .mutation(async (opts) => {
- const incidentUpdateToDelete = await opts.ctx.db
- .select()
- .from(incidentUpdate)
- .where(and(eq(incidentUpdate.id, opts.input.id)))
- // FIXME: check if incident related to workspaceId
- // .innerJoin(incident, inArray(incident.workspaceId, workspaceIds))
- .get();
-
- if (!incidentUpdateToDelete) return;
-
- await opts.ctx.db
- .delete(incidentUpdate)
- .where(eq(incidentUpdate.id, opts.input.id))
- .run();
- }),
-
- getIncidentById: protectedProcedure
- .input(z.object({ id: z.number() }))
- .query(async (opts) => {
- const selectIncidentSchemaWithRelation = selectIncidentSchema.extend({
- status: incidentStatusSchema.default("investigating"), // TODO: remove!
- monitorsToIncidents: z
- .array(z.object({ incidentId: z.number(), monitorId: z.number() }))
- .default([]),
- pagesToIncidents: z
- .array(z.object({ incidentId: z.number(), pageId: z.number() }))
- .default([]),
- incidentUpdates: z.array(selectIncidentUpdateSchema),
- date: z.date().default(new Date()),
- });
-
- const data = await opts.ctx.db.query.incident.findFirst({
- where: and(
- eq(incident.id, opts.input.id),
- eq(incident.workspaceId, opts.ctx.workspace.id),
- ),
- with: {
- monitorsToIncidents: true,
- pagesToIncidents: true,
- incidentUpdates: {
- orderBy: (incidentUpdate, { desc }) => [
- desc(incidentUpdate.createdAt),
- ],
- },
- },
- });
-
- return selectIncidentSchemaWithRelation.parse(data);
- }),
-
- getIncidentUpdateById: protectedProcedure
- .input(z.object({ id: z.number() }))
- .query(async (opts) => {
- const data = await opts.ctx.db.query.incidentUpdate.findFirst({
- where: and(eq(incidentUpdate.id, opts.input.id)),
- });
- return selectIncidentUpdateSchema.parse(data);
- }),
-
- getIncidentByWorkspace: protectedProcedure.query(async (opts) => {
- // FIXME: can we get rid of that?
- const selectIncidentSchemaWithRelation = selectIncidentSchema.extend({
- status: incidentStatusSchema.default("investigating"), // TODO: remove!
- monitorsToIncidents: z
- .array(
- z.object({
- incidentId: z.number(),
- monitorId: z.number(),
- monitor: selectMonitorSchema,
- }),
- )
- .default([]),
- incidentUpdates: z.array(selectIncidentUpdateSchema),
- });
-
- const result = await opts.ctx.db.query.incident.findMany({
- where: eq(incident.workspaceId, opts.ctx.workspace.id),
- with: {
- monitorsToIncidents: { with: { monitor: true } },
- incidentUpdates: {
- orderBy: (incidentUpdate, { desc }) => [
- desc(incidentUpdate.createdAt),
- ],
- },
- },
- orderBy: (incident, { desc }) => [desc(incident.updatedAt)],
- });
-
- return z.array(selectIncidentSchemaWithRelation).parse(result);
- }),
-});
diff --git a/packages/api/src/router/page.test.ts b/packages/api/src/router/page.test.ts
index 71b6079f1..2d23f42de 100644
--- a/packages/api/src/router/page.test.ts
+++ b/packages/api/src/router/page.test.ts
@@ -20,7 +20,7 @@ test("Get Test Page", async () => {
customDomain: "",
description: "hello",
icon: "https://www.openstatus.dev/favicon.ico",
- incidents: [],
+ statusReports: [],
monitors: [
{
active: true,
diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.ts
index bdb40168d..7c9757ae7 100644
--- a/packages/api/src/router/page.ts
+++ b/packages/api/src/router/page.ts
@@ -3,14 +3,14 @@ import { z } from "zod";
import { and, eq, inArray, or, sql } from "@openstatus/db";
import {
- incident,
insertPageSchema,
monitor,
- monitorsToIncidents,
monitorsToPages,
+ monitorsToStatusReport,
page,
- pagesToIncidents,
+ pagesToStatusReports,
selectPublicPageSchemaWithRelation,
+ statusReport,
} from "@openstatus/db/src/schema";
import { allPlans } from "@openstatus/plans";
@@ -74,7 +74,6 @@ export const pageRouter = createTRPCRouter({
),
with: {
monitorsToPages: { with: { monitor: true } },
- // incidents: true
},
});
}),
@@ -169,52 +168,57 @@ export const pageRouter = createTRPCRouter({
const monitorsToPagesResult = await opts.ctx.db
.select()
.from(monitorsToPages)
- .where(eq(monitorsToPages.pageId, result.id))
+ .leftJoin(monitor, eq(monitorsToPages.monitorId, monitor.id))
+ .where(
+ // make sur only active monitors are returned!
+ and(eq(monitorsToPages.pageId, result.id), eq(monitor.active, true)),
+ )
.all();
const monitorsId = monitorsToPagesResult.map(
- ({ monitorId }) => monitorId,
+ ({ monitors_to_pages }) => monitors_to_pages.monitorId,
);
- const monitorsToIncidentsResult =
+ const monitorsToStatusReportResult =
monitorsId.length > 0
? await opts.ctx.db
.select()
- .from(monitorsToIncidents)
- .where(inArray(monitorsToIncidents.monitorId, monitorsId))
+ .from(monitorsToStatusReport)
+ .where(inArray(monitorsToStatusReport.monitorId, monitorsId))
.all()
: [];
- const incidentsToPagesResult = await opts.ctx.db
+ const statusReportsToPagesResult = await opts.ctx.db
.select()
- .from(pagesToIncidents)
- .where(eq(pagesToIncidents.pageId, result.id))
+ .from(pagesToStatusReports)
+ .where(eq(pagesToStatusReports.pageId, result.id))
.all();
- const monitorIncidentIds = monitorsToIncidentsResult.map(
- ({ incidentId }) => incidentId,
+ const monitorStatusReportIds = monitorsToStatusReportResult.map(
+ ({ statusReportId }) => statusReportId,
);
- const pageIncidentIds = incidentsToPagesResult.map(
- ({ incidentId }) => incidentId,
+ const pageStatusReportIds = statusReportsToPagesResult.map(
+ ({ statusReportId }) => statusReportId,
);
- const incidentIds = Array.from(
- new Set([...monitorIncidentIds, ...pageIncidentIds]),
+ const statusReportIds = Array.from(
+ new Set([...monitorStatusReportIds, ...pageStatusReportIds]),
);
- const incidents =
- incidentIds.length > 0
- ? await opts.ctx.db.query.incident.findMany({
- where: or(inArray(incident.id, incidentIds)),
+ const statusReports =
+ statusReportIds.length > 0
+ ? await opts.ctx.db.query.statusReport.findMany({
+ where: or(inArray(statusReport.id, statusReportIds)),
with: {
- incidentUpdates: true,
- monitorsToIncidents: true,
- pagesToIncidents: true,
+ statusReportUpdates: true,
+ monitorsToStatusReports: true,
+ pagesToStatusReports: true,
},
})
: [];
+ // TODO: monitorsToPagesResult has the result already, no need to query again
const monitors =
monitorsId.length > 0
? await opts.ctx.db
@@ -229,7 +233,7 @@ export const pageRouter = createTRPCRouter({
return selectPublicPageSchemaWithRelation.parse({
...result,
monitors,
- incidents,
+ statusReports,
});
}),
diff --git a/packages/api/src/router/statusReport.ts b/packages/api/src/router/statusReport.ts
new file mode 100644
index 000000000..e7872312e
--- /dev/null
+++ b/packages/api/src/router/statusReport.ts
@@ -0,0 +1,329 @@
+import { z } from "zod";
+
+import { and, eq, inArray } from "@openstatus/db";
+import {
+ insertStatusReportSchema,
+ insertStatusReportUpdateSchema,
+ monitorsToStatusReport,
+ pagesToStatusReports,
+ selectMonitorSchema,
+ selectStatusReportSchema,
+ selectStatusReportUpdateSchema,
+ statusReport,
+ statusReportStatusSchema,
+ statusReportUpdate,
+} from "@openstatus/db/src/schema";
+
+import { createTRPCRouter, protectedProcedure } from "../trpc";
+
+export const statusReportRouter = createTRPCRouter({
+ createStatusReport: protectedProcedure
+ .input(insertStatusReportSchema)
+ .mutation(async (opts) => {
+ const { id, monitors, pages, date, message, ...statusReportInput } =
+ opts.input;
+
+ const newStatusReport = await opts.ctx.db
+ .insert(statusReport)
+ .values({
+ workspaceId: opts.ctx.workspace.id,
+ ...statusReportInput,
+ })
+ .returning()
+ .get();
+
+ if (Boolean(monitors.length)) {
+ await opts.ctx.db
+ .insert(monitorsToStatusReport)
+ .values(
+ monitors.map((monitor) => ({
+ monitorId: monitor,
+ statusReportId: newStatusReport.id,
+ })),
+ )
+ .returning()
+ .get();
+ }
+
+ if (Boolean(pages.length)) {
+ await opts.ctx.db
+ .insert(pagesToStatusReports)
+ .values(
+ pages.map((page) => ({
+ pageId: page,
+ statusReportId: newStatusReport.id,
+ })),
+ )
+ .returning()
+ .get();
+ }
+
+ return newStatusReport;
+ }),
+
+ createStatusReportUpdate: protectedProcedure
+ .input(insertStatusReportUpdateSchema)
+ .mutation(async (opts) => {
+ // update parent status report with latest status
+ await opts.ctx.db
+ .update(statusReport)
+ .set({ status: opts.input.status, updatedAt: new Date() })
+ .where(
+ and(
+ eq(statusReport.id, opts.input.statusReportId),
+ eq(statusReport.workspaceId, opts.ctx.workspace.id),
+ ),
+ )
+ .returning()
+ .get();
+
+ const { id, ...statusReportUpdateInput } = opts.input;
+ return await opts.ctx.db
+ .insert(statusReportUpdate)
+ .values(statusReportUpdateInput)
+ .returning()
+ .get();
+ }),
+
+ updateStatusReport: protectedProcedure
+ .input(insertStatusReportSchema)
+ .mutation(async (opts) => {
+ const { monitors, pages, ...statusReportInput } = opts.input;
+
+ if (!statusReportInput.id) return;
+
+ console.log({ pages });
+
+ const { title, status } = statusReportInput;
+
+ const currentStatusReport = await opts.ctx.db
+ .update(statusReport)
+ .set({ title, status, updatedAt: new Date() })
+ .where(
+ and(
+ eq(statusReport.id, statusReportInput.id),
+ eq(statusReport.workspaceId, opts.ctx.workspace.id),
+ ),
+ )
+ .returning()
+ .get();
+
+ const currentMonitorsToStatusReport = await opts.ctx.db
+ .select()
+ .from(monitorsToStatusReport)
+ .where(
+ eq(monitorsToStatusReport.statusReportId, currentStatusReport.id),
+ )
+ .all();
+
+ const addedMonitors = monitors.filter(
+ (x) =>
+ !currentMonitorsToStatusReport
+ .map(({ monitorId }) => monitorId)
+ .includes(x),
+ );
+
+ if (Boolean(addedMonitors.length)) {
+ const values = addedMonitors.map((monitorId) => ({
+ monitorId: monitorId,
+ statusReportId: currentStatusReport.id,
+ }));
+
+ await opts.ctx.db.insert(monitorsToStatusReport).values(values).run();
+ }
+
+ const removedMonitors = currentMonitorsToStatusReport
+ .map(({ monitorId }) => monitorId)
+ .filter((x) => !monitors?.includes(x));
+
+ if (Boolean(removedMonitors.length)) {
+ await opts.ctx.db
+ .delete(monitorsToStatusReport)
+ .where(
+ and(
+ eq(monitorsToStatusReport.statusReportId, currentStatusReport.id),
+ inArray(monitorsToStatusReport.monitorId, removedMonitors),
+ ),
+ )
+ .run();
+ }
+
+ const currentPagesToStatusReports = await opts.ctx.db
+ .select()
+ .from(pagesToStatusReports)
+ .where(eq(pagesToStatusReports.statusReportId, currentStatusReport.id))
+ .all();
+
+ const addedPages = pages?.filter(
+ (x) =>
+ !currentPagesToStatusReports.map(({ pageId }) => pageId)?.includes(x),
+ );
+
+ if (Boolean(addedPages.length)) {
+ const values = addedPages.map((pageId) => ({
+ pageId,
+ statusReportId: currentStatusReport.id,
+ }));
+
+ await opts.ctx.db.insert(pagesToStatusReports).values(values).run();
+ }
+
+ const removedPages = currentPagesToStatusReports
+ .map(({ pageId }) => pageId)
+ .filter((x) => !pages?.includes(x));
+
+ console.log({
+ currentPagesToStatusReports,
+ removedPages,
+ pages,
+ addedPages,
+ });
+
+ if (Boolean(removedPages.length)) {
+ await opts.ctx.db
+ .delete(pagesToStatusReports)
+ .where(
+ and(
+ eq(pagesToStatusReports.statusReportId, currentStatusReport.id),
+ inArray(pagesToStatusReports.pageId, removedPages),
+ ),
+ )
+ .run();
+ }
+
+ return currentStatusReport;
+ }),
+
+ updateStatusReportUpdate: protectedProcedure
+ .input(insertStatusReportUpdateSchema)
+ .mutation(async (opts) => {
+ const statusReportUpdateInput = opts.input;
+
+ if (!statusReportUpdateInput.id) return;
+
+ const currentStatusReportUpdate = await opts.ctx.db
+ .update(statusReportUpdate)
+ .set(statusReportUpdateInput)
+ .where(eq(statusReportUpdate.id, statusReportUpdateInput.id))
+ .returning()
+ .get();
+
+ return currentStatusReportUpdate;
+ }),
+
+ deleteStatusReport: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .mutation(async (opts) => {
+ const statusReportToDelete = await opts.ctx.db
+ .select()
+ .from(statusReport)
+ .where(
+ and(
+ eq(statusReport.id, opts.input.id),
+ eq(statusReport.workspaceId, opts.ctx.workspace.id),
+ ),
+ )
+ .get();
+ if (!statusReportToDelete) return;
+
+ await opts.ctx.db
+ .delete(statusReport)
+ .where(eq(statusReport.id, statusReportToDelete.id))
+ .run();
+ }),
+
+ deleteStatusReportUpdate: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .mutation(async (opts) => {
+ const statusReportUpdateToDelete = await opts.ctx.db
+ .select()
+ .from(statusReportUpdate)
+ .where(and(eq(statusReportUpdate.id, opts.input.id)))
+ .get();
+
+ if (!statusReportUpdateToDelete) return;
+
+ await opts.ctx.db
+ .delete(statusReportUpdate)
+ .where(eq(statusReportUpdate.id, opts.input.id))
+ .run();
+ }),
+
+ getStatusReportById: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async (opts) => {
+ const selectStatusReportSchemaWithRelation =
+ selectStatusReportSchema.extend({
+ status: statusReportStatusSchema.default("investigating"), // TODO: remove!
+ monitorsToStatusReports: z
+ .array(
+ z.object({ statusReportId: z.number(), monitorId: z.number() }),
+ )
+ .default([]),
+ pagesToStatusReports: z
+ .array(z.object({ statusReportId: z.number(), pageId: z.number() }))
+ .default([]),
+ statusReportUpdates: z.array(selectStatusReportUpdateSchema),
+ date: z.date().default(new Date()),
+ });
+
+ const data = await opts.ctx.db.query.statusReport.findFirst({
+ where: and(
+ eq(statusReport.id, opts.input.id),
+ eq(statusReport.workspaceId, opts.ctx.workspace.id),
+ ),
+ with: {
+ monitorsToStatusReports: true,
+ pagesToStatusReports: true,
+ statusReportUpdates: {
+ orderBy: (statusReportUpdate, { desc }) => [
+ desc(statusReportUpdate.createdAt),
+ ],
+ },
+ },
+ });
+
+ return selectStatusReportSchemaWithRelation.parse(data);
+ }),
+
+ getStatusReportUpdateById: protectedProcedure
+ .input(z.object({ id: z.number() }))
+ .query(async (opts) => {
+ const data = await opts.ctx.db.query.statusReportUpdate.findFirst({
+ where: and(eq(statusReportUpdate.id, opts.input.id)),
+ });
+ return selectStatusReportUpdateSchema.parse(data);
+ }),
+
+ getStatusReportByWorkspace: protectedProcedure.query(async (opts) => {
+ // FIXME: can we get rid of that?
+ const selectStatusSchemaWithRelation = selectStatusReportSchema.extend({
+ status: statusReportStatusSchema.default("investigating"), // TODO: remove!
+ monitorsToStatusReports: z
+ .array(
+ z.object({
+ statusReportId: z.number(),
+ monitorId: z.number(),
+ monitor: selectMonitorSchema,
+ }),
+ )
+ .default([]),
+ statusReportUpdates: z.array(selectStatusReportUpdateSchema),
+ });
+
+ const result = await opts.ctx.db.query.statusReport.findMany({
+ where: eq(statusReport.workspaceId, opts.ctx.workspace.id),
+ with: {
+ monitorsToStatusReports: { with: { monitor: true } },
+ statusReportUpdates: {
+ orderBy: (statusReportUpdate, { desc }) => [
+ desc(statusReportUpdate.createdAt),
+ ],
+ },
+ },
+ orderBy: (statusReport, { desc }) => [desc(statusReport.updatedAt)],
+ });
+ console.log(result);
+ return z.array(selectStatusSchemaWithRelation).parse(result);
+ }),
+});
diff --git a/packages/db/drizzle/0011_bright_jazinda.sql b/packages/db/drizzle/0011_bright_jazinda.sql
new file mode 100644
index 000000000..679af1c94
--- /dev/null
+++ b/packages/db/drizzle/0011_bright_jazinda.sql
@@ -0,0 +1,7 @@
+ALTER TABLE `incidents_to_monitors` RENAME TO `status_report_to_monitors`;--> statement-breakpoint
+ALTER TABLE `incidents_to_pages` RENAME TO `status_reports_to_pages`;--> statement-breakpoint
+ALTER TABLE `incident_update` RENAME TO `status_report_update`;--> statement-breakpoint
+ALTER TABLE `incident` RENAME TO `status_report`; --> statement-breakpoint
+ALTER TABLE `status_report_to_monitors` RENAME COLUMN `incident_id` TO `status_report_id`;--> statement-breakpoint
+ALTER TABLE `status_reports_to_pages` RENAME COLUMN `incident_id` TO `status_report_id`;--> statement-breakpoint
+ALTER TABLE `status_report_update` RENAME COLUMN `incident_id` TO `status_report_id`;
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/0011_snapshot.json b/packages/db/drizzle/meta/0011_snapshot.json
new file mode 100644
index 000000000..ab3d82b5e
--- /dev/null
+++ b/packages/db/drizzle/meta/0011_snapshot.json
@@ -0,0 +1,1099 @@
+{
+ "version": "5",
+ "dialect": "sqlite",
+ "id": "21a5d3a2-6aab-4f67-8385-19d905e1a232",
+ "prevId": "452e7037-85cf-4d9a-b4e2-375a695d5fa8",
+ "tables": {
+ "status_report_to_monitors": {
+ "name": "status_report_to_monitors",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "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_incident_id_status_report_id_fk": {
+ "name": "status_report_to_monitors_incident_id_status_report_id_fk",
+ "tableFrom": "status_report_to_monitors",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "status_report_to_monitors_monitor_id_incident_id_pk": {
+ "columns": [
+ "incident_id",
+ "monitor_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "status_reports_to_pages": {
+ "name": "status_reports_to_pages",
+ "columns": {
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "status_reports_to_pages_page_id_page_id_fk": {
+ "name": "status_reports_to_pages_page_id_page_id_fk",
+ "tableFrom": "status_reports_to_pages",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "status_reports_to_pages_incident_id_status_report_id_fk": {
+ "name": "status_reports_to_pages_incident_id_status_report_id_fk",
+ "tableFrom": "status_reports_to_pages",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "status_reports_to_pages_page_id_incident_id_pk": {
+ "columns": [
+ "incident_id",
+ "page_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "status_report_update": {
+ "name": "status_report_update",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text(4)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "date": {
+ "name": "date",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message": {
+ "name": "message",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "incident_id": {
+ "name": "incident_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "status_report_update_incident_id_status_report_id_fk": {
+ "name": "status_report_update_incident_id_status_report_id_fk",
+ "tableFrom": "status_report_update",
+ "tableTo": "status_report",
+ "columnsFrom": [
+ "incident_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "status_report": {
+ "name": "status_report",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "status_report_workspace_id_workspace_id_fk": {
+ "name": "status_report_workspace_id_workspace_id_fk",
+ "tableFrom": "status_report",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "integration": {
+ "name": "integration",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "credential": {
+ "name": "credential",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "data": {
+ "name": "data",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "integration_workspace_id_workspace_id_fk": {
+ "name": "integration_workspace_id_workspace_id_fk",
+ "tableFrom": "integration",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "page": {
+ "name": "page",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "custom_domain": {
+ "name": "custom_domain",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "published": {
+ "name": "published",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "page_slug_unique": {
+ "name": "page_slug_unique",
+ "columns": [
+ "slug"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "page_workspace_id_workspace_id_fk": {
+ "name": "page_workspace_id_workspace_id_fk",
+ "tableFrom": "page",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitor": {
+ "name": "monitor",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "job_type": {
+ "name": "job_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "periodicity": {
+ "name": "periodicity",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'other'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "active": {
+ "name": "active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "regions": {
+ "name": "regions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "url": {
+ "name": "url",
+ "type": "text(2048)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "headers": {
+ "name": "headers",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "body": {
+ "name": "body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "method": {
+ "name": "method",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'GET'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitor_workspace_id_workspace_id_fk": {
+ "name": "monitor_workspace_id_workspace_id_fk",
+ "tableFrom": "monitor",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "monitors_to_pages": {
+ "name": "monitors_to_pages",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "page_id": {
+ "name": "page_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "monitors_to_pages_monitor_id_monitor_id_fk": {
+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",
+ "tableFrom": "monitors_to_pages",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "monitors_to_pages_page_id_page_id_fk": {
+ "name": "monitors_to_pages_page_id_page_id_fk",
+ "tableFrom": "monitors_to_pages",
+ "tableTo": "page",
+ "columnsFrom": [
+ "page_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "monitors_to_pages_monitor_id_page_id_pk": {
+ "columns": [
+ "monitor_id",
+ "page_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "user": {
+ "name": "user",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tenant_id": {
+ "name": "tenant_id",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "first_name": {
+ "name": "first_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "last_name": {
+ "name": "last_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "photo_url": {
+ "name": "photo_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "user_tenant_id_unique": {
+ "name": "user_tenant_id_unique",
+ "columns": [
+ "tenant_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "users_to_workspaces": {
+ "name": "users_to_workspaces",
+ "columns": {
+ "user_id": {
+ "name": "user_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "users_to_workspaces_user_id_user_id_fk": {
+ "name": "users_to_workspaces_user_id_user_id_fk",
+ "tableFrom": "users_to_workspaces",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "users_to_workspaces_workspace_id_workspace_id_fk": {
+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",
+ "tableFrom": "users_to_workspaces",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "users_to_workspaces_user_id_workspace_id_pk": {
+ "columns": [
+ "user_id",
+ "workspace_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "workspace": {
+ "name": "workspace",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripe_id": {
+ "name": "stripe_id",
+ "type": "text(256)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "subscription_id": {
+ "name": "subscription_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "plan": {
+ "name": "plan",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "ends_at": {
+ "name": "ends_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "paid_until": {
+ "name": "paid_until",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {
+ "workspace_slug_unique": {
+ "name": "workspace_slug_unique",
+ "columns": [
+ "slug"
+ ],
+ "isUnique": true
+ },
+ "workspace_stripe_id_unique": {
+ "name": "workspace_stripe_id_unique",
+ "columns": [
+ "stripe_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "notification": {
+ "name": "notification",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "data": {
+ "name": "data",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "(strftime('%s', 'now'))"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "notification_workspace_id_workspace_id_fk": {
+ "name": "notification_workspace_id_workspace_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "workspace",
+ "columnsFrom": [
+ "workspace_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "notifications_to_monitors": {
+ "name": "notifications_to_monitors",
+ "columns": {
+ "monitor_id": {
+ "name": "monitor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "notification_id": {
+ "name": "notification_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "notifications_to_monitors_monitor_id_monitor_id_fk": {
+ "name": "notifications_to_monitors_monitor_id_monitor_id_fk",
+ "tableFrom": "notifications_to_monitors",
+ "tableTo": "monitor",
+ "columnsFrom": [
+ "monitor_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "notifications_to_monitors_notification_id_notification_id_fk": {
+ "name": "notifications_to_monitors_notification_id_notification_id_fk",
+ "tableFrom": "notifications_to_monitors",
+ "tableTo": "notification",
+ "columnsFrom": [
+ "notification_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "notifications_to_monitors_monitor_id_notification_id_pk": {
+ "columns": [
+ "monitor_id",
+ "notification_id"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ },
+ "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"
+ ]
+ }
+ },
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {
+ "\"incidents_to_monitors\"": "\"status_report_to_monitors\"",
+ "\"incidents_to_pages\"": "\"status_reports_to_pages\"",
+ "\"incident_update\"": "\"status_report_update\"",
+ "\"incident\"": "\"status_report\""
+ },
+ "columns": {}
+ }
+}
\ No newline at end of file
diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json
index 5d4f5c781..fc6ef345c 100644
--- a/packages/db/drizzle/meta/_journal.json
+++ b/packages/db/drizzle/meta/_journal.json
@@ -78,6 +78,13 @@
"when": 1700586221141,
"tag": "0010_lame_songbird",
"breakpoints": true
+ },
+ {
+ "idx": 11,
+ "version": "5",
+ "when": 1701100570578,
+ "tag": "0011_bright_jazinda",
+ "breakpoints": true
}
]
-}
\ No newline at end of file
+}
diff --git a/packages/db/src/schema/incidents/incident.ts b/packages/db/src/schema/incidents/incident.ts
deleted file mode 100644
index c02c8c28e..000000000
--- a/packages/db/src/schema/incidents/incident.ts
+++ /dev/null
@@ -1,126 +0,0 @@
-import { relations, sql } from "drizzle-orm";
-import {
- integer,
- primaryKey,
- sqliteTable,
- text,
-} from "drizzle-orm/sqlite-core";
-
-import { monitor } from "../monitors";
-import { page } from "../pages";
-import { workspace } from "../workspaces";
-
-export const incidentStatus = [
- "investigating",
- "identified",
- "monitoring",
- "resolved",
-] as const;
-
-export const incident = sqliteTable("incident", {
- id: integer("id").primaryKey(),
- status: text("status", { enum: incidentStatus }).notNull(),
- title: text("title", { length: 256 }).notNull(),
-
- workspaceId: integer("workspace_id").references(() => workspace.id),
-
- createdAt: integer("created_at", { mode: "timestamp" }).default(
- sql`(strftime('%s', 'now'))`,
- ),
- updatedAt: integer("updated_at", { mode: "timestamp" }).default(
- sql`(strftime('%s', 'now'))`,
- ),
-});
-
-export const incidentUpdate = sqliteTable("incident_update", {
- id: integer("id").primaryKey(),
-
- status: text("status", incidentStatus).notNull(),
- date: integer("date", { mode: "timestamp" }).notNull(),
- message: text("message").notNull(),
-
- incidentId: integer("incident_id")
- .references(() => incident.id, { onDelete: "cascade" })
- .notNull(),
- createdAt: integer("created_at", { mode: "timestamp" }).default(
- sql`(strftime('%s', 'now'))`,
- ),
- updatedAt: integer("updated_at", { mode: "timestamp" }).default(
- sql`(strftime('%s', 'now'))`,
- ),
-});
-
-export const incidentRelations = relations(incident, ({ one, many }) => ({
- monitorsToIncidents: many(monitorsToIncidents),
- pagesToIncidents: many(pagesToIncidents),
- incidentUpdates: many(incidentUpdate),
- workspace: one(workspace, {
- fields: [incident.workspaceId],
- references: [workspace.id],
- }),
-}));
-
-export const incidentUpdateRelations = relations(incidentUpdate, ({ one }) => ({
- incident: one(incident, {
- fields: [incidentUpdate.incidentId],
- references: [incident.id],
- }),
-}));
-
-export const monitorsToIncidents = sqliteTable(
- "incidents_to_monitors",
- {
- monitorId: integer("monitor_id")
- .notNull()
- .references(() => monitor.id, { onDelete: "cascade" }),
- incidentId: integer("incident_id")
- .notNull()
- .references(() => incident.id, { onDelete: "cascade" }),
- },
- (t) => ({
- pk: primaryKey(t.monitorId, t.incidentId),
- }),
-);
-
-export const monitorsToIncidentsRelations = relations(
- monitorsToIncidents,
- ({ one }) => ({
- monitor: one(monitor, {
- fields: [monitorsToIncidents.monitorId],
- references: [monitor.id],
- }),
- incident: one(incident, {
- fields: [monitorsToIncidents.incidentId],
- references: [incident.id],
- }),
- }),
-);
-
-export const pagesToIncidents = sqliteTable(
- "incidents_to_pages",
- {
- pageId: integer("page_id")
- .notNull()
- .references(() => page.id, { onDelete: "cascade" }),
- incidentId: integer("incident_id")
- .notNull()
- .references(() => incident.id, { onDelete: "cascade" }),
- },
- (t) => ({
- pk: primaryKey(t.pageId, t.incidentId),
- }),
-);
-
-export const pagesToIncidentsRelations = relations(
- pagesToIncidents,
- ({ one }) => ({
- page: one(page, {
- fields: [pagesToIncidents.pageId],
- references: [page.id],
- }),
- incident: one(incident, {
- fields: [pagesToIncidents.incidentId],
- references: [incident.id],
- }),
- }),
-);
diff --git a/packages/db/src/schema/incidents/validation.ts b/packages/db/src/schema/incidents/validation.ts
deleted file mode 100644
index c8965b49d..000000000
--- a/packages/db/src/schema/incidents/validation.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { createInsertSchema, createSelectSchema } from "drizzle-zod";
-import * as z from "zod";
-
-import { incident, incidentStatus, incidentUpdate } from "./incident";
-
-export const incidentStatusSchema = z.enum(incidentStatus);
-
-export const insertIncidentUpdateSchema = createInsertSchema(incidentUpdate, {
- status: incidentStatusSchema,
-});
-
-export const insertIncidentSchema = createInsertSchema(incident, {
- status: incidentStatusSchema,
-})
- .extend({
- date: z.date().optional().default(new Date()),
- /**
- * relationship to monitors and pages
- */
- monitors: z.number().array().optional().default([]),
- pages: z.number().array().optional().default([]),
- })
- .extend({
- /**
- * message for the `InsertIncidentUpdate`
- */
- message: z.string(),
- });
-
-export const selectIncidentSchema = createSelectSchema(incident, {
- status: incidentStatusSchema,
-});
-
-export const selectIncidentUpdateSchema = createSelectSchema(incidentUpdate, {
- status: incidentStatusSchema,
-});
-
-export type InsertIncident = z.infer<typeof insertIncidentSchema>;
-export type Incident = z.infer<typeof selectIncidentSchema>;
-export type InsertIncidentUpdate = z.infer<typeof insertIncidentUpdateSchema>;
-export type IncidentUpdate = z.infer<typeof selectIncidentUpdateSchema>;
diff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.ts
index 9cba6eee0..0a96d55ce 100644
--- a/packages/db/src/schema/index.ts
+++ b/packages/db/src/schema/index.ts
@@ -1,4 +1,4 @@
-export * from "./incidents";
+export * from "./status_reports";
export * from "./integration";
export * from "./pages";
export * from "./monitors";
diff --git a/packages/db/src/schema/monitors/monitor.ts b/packages/db/src/schema/monitors/monitor.ts
index d9e54073a..c2ff2da5a 100644
--- a/packages/db/src/schema/monitors/monitor.ts
+++ b/packages/db/src/schema/monitors/monitor.ts
@@ -6,9 +6,9 @@ import {
text,
} from "drizzle-orm/sqlite-core";
-import { monitorsToIncidents } from "../incidents";
import { notificationsToMonitors } from "../notifications";
import { page } from "../pages";
+import { monitorsToStatusReport } from "../status_reports";
import { workspace } from "../workspaces";
import {
monitorJobTypes,
@@ -50,7 +50,7 @@ export const monitor = sqliteTable("monitor", {
export const monitorRelation = relations(monitor, ({ one, many }) => ({
monitorsToPages: many(monitorsToPages),
- monitorsToIncidents: many(monitorsToIncidents),
+ monitorsToStatusReports: many(monitorsToStatusReport),
workspace: one(workspace, {
fields: [monitor.workspaceId],
references: [workspace.id],
diff --git a/packages/db/src/schema/pages/page.ts b/packages/db/src/schema/pages/page.ts
index 333593992..0dcaec9cd 100644
--- a/packages/db/src/schema/pages/page.ts
+++ b/packages/db/src/schema/pages/page.ts
@@ -1,8 +1,8 @@
import { relations, sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
-import { pagesToIncidents } from "../incidents";
import { monitorsToPages } from "../monitors";
+import { pagesToStatusReports } from "../status_reports";
import { workspace } from "../workspaces";
export const page = sqliteTable("page", {
@@ -29,7 +29,7 @@ export const page = sqliteTable("page", {
export const pageRelations = relations(page, ({ many, one }) => ({
monitorsToPages: many(monitorsToPages),
- pagesToIncidents: many(pagesToIncidents),
+ pagesToStatusReports: many(pagesToStatusReports),
workspace: one(workspace, {
fields: [page.workspaceId],
references: [workspace.id],
diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.ts
index 2af6d4353..fcd7bda9a 100644
--- a/packages/db/src/schema/shared.ts
+++ b/packages/db/src/schema/shared.ts
@@ -1,20 +1,25 @@
import { z } from "zod";
-import { selectIncidentSchema, selectIncidentUpdateSchema } from "./incidents";
import { selectMonitorSchema } from "./monitors";
import { selectPageSchema } from "./pages";
+import {
+ selectStatusReportSchema,
+ selectStatusReportUpdateSchema,
+} from "./status_reports";
-export const selectIncidentsPageSchema = z.array(
- selectIncidentSchema.extend({
- incidentUpdates: z.array(selectIncidentUpdateSchema),
- monitorsToIncidents: z.array(
- z.object({ monitorId: z.number(), incidentId: z.number() }),
- ),
+// FIXME: delete this file!
+
+export const selectStatusReportPageSchema = z.array(
+ selectStatusReportSchema.extend({
+ statusReportUpdates: z.array(selectStatusReportUpdateSchema).default([]),
+ monitorsToStatusReport: z
+ .array(z.object({ monitorId: z.number(), statusReportId: z.number() }))
+ .default([]),
}),
);
export const selectPageSchemaWithRelation = selectPageSchema.extend({
monitors: z.array(selectMonitorSchema),
- incidents: selectIncidentsPageSchema,
+ statusReports: selectStatusReportPageSchema,
});
export const selectPublicMonitorSchema = selectMonitorSchema.omit({
@@ -27,7 +32,7 @@ export const selectPublicMonitorSchema = selectMonitorSchema.omit({
export const selectPublicPageSchemaWithRelation = selectPageSchema
.extend({
monitors: z.array(selectPublicMonitorSchema),
- incidents: selectIncidentsPageSchema,
+ statusReports: selectStatusReportPageSchema,
})
.omit({
workspaceId: true,
diff --git a/packages/db/src/schema/incidents/index.ts b/packages/db/src/schema/status_reports/index.ts
similarity index 65%
rename from packages/db/src/schema/incidents/index.ts
rename to packages/db/src/schema/status_reports/index.ts
index 079c283be..b1b553d60 100644
--- a/packages/db/src/schema/incidents/index.ts
+++ b/packages/db/src/schema/status_reports/index.ts
@@ -1,3 +1,3 @@
-export * from "./incident";
+export * from "./status_reports";
export * from "./validation";
export type * from "./validation";
diff --git a/packages/db/src/schema/status_reports/status_reports.ts b/packages/db/src/schema/status_reports/status_reports.ts
new file mode 100644
index 000000000..ec4817246
--- /dev/null
+++ b/packages/db/src/schema/status_reports/status_reports.ts
@@ -0,0 +1,132 @@
+import { relations, sql } from "drizzle-orm";
+import {
+ integer,
+ primaryKey,
+ sqliteTable,
+ text,
+} from "drizzle-orm/sqlite-core";
+
+import { monitor } from "../monitors";
+import { page } from "../pages";
+import { workspace } from "../workspaces";
+
+export const statusReportStatus = [
+ "investigating",
+ "identified",
+ "monitoring",
+ "resolved",
+] as const;
+
+export const statusReport = sqliteTable("status_report", {
+ id: integer("id").primaryKey(),
+ status: text("status", { enum: statusReportStatus }).notNull(),
+ title: text("title", { length: 256 }).notNull(),
+
+ workspaceId: integer("workspace_id").references(() => workspace.id),
+
+ createdAt: integer("created_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`,
+ ),
+ updatedAt: integer("updated_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`,
+ ),
+});
+
+export const statusReportUpdate = sqliteTable("status_report_update", {
+ id: integer("id").primaryKey(),
+
+ status: text("status", statusReportStatus).notNull(),
+ date: integer("date", { mode: "timestamp" }).notNull(),
+ message: text("message").notNull(),
+
+ statusReportId: integer("status_report_id")
+ .references(() => statusReport.id, { onDelete: "cascade" })
+ .notNull(),
+ createdAt: integer("created_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`,
+ ),
+ updatedAt: integer("updated_at", { mode: "timestamp" }).default(
+ sql`(strftime('%s', 'now'))`,
+ ),
+});
+
+export const StatusReportRelations = relations(
+ statusReport,
+ ({ one, many }) => ({
+ monitorsToStatusReports: many(monitorsToStatusReport),
+ pagesToStatusReports: many(pagesToStatusReports),
+ statusReportUpdates: many(statusReportUpdate),
+ workspace: one(workspace, {
+ fields: [statusReport.workspaceId],
+ references: [workspace.id],
+ }),
+ }),
+);
+
+export const statusReportUpdateRelations = relations(
+ statusReportUpdate,
+ ({ one }) => ({
+ statusReport: one(statusReport, {
+ fields: [statusReportUpdate.statusReportId],
+ references: [statusReport.id],
+ }),
+ }),
+);
+
+export const monitorsToStatusReport = sqliteTable(
+ "status_report_to_monitors",
+ {
+ monitorId: integer("monitor_id")
+ .notNull()
+ .references(() => monitor.id, { onDelete: "cascade" }),
+ statusReportId: integer("status_report_id")
+ .notNull()
+ .references(() => statusReport.id, { onDelete: "cascade" }),
+ },
+ (t) => ({
+ pk: primaryKey(t.monitorId, t.statusReportId),
+ }),
+);
+
+export const monitorsToStatusReportRelations = relations(
+ monitorsToStatusReport,
+ ({ one }) => ({
+ monitor: one(monitor, {
+ fields: [monitorsToStatusReport.monitorId],
+ references: [monitor.id],
+ }),
+ statusReport: one(statusReport, {
+ fields: [monitorsToStatusReport.statusReportId],
+ references: [statusReport.id],
+ }),
+ }),
+);
+
+export const pagesToStatusReports = sqliteTable(
+ "status_reports_to_pages",
+ {
+ pageId: integer("page_id")
+ .notNull()
+ .references(() => page.id, { onDelete: "cascade" }),
+ statusReportId: integer("status_report_id")
+ .notNull()
+ .references(() => statusReport.id, { onDelete: "cascade" }),
+ },
+ (t) => ({
+ pk: primaryKey(t.pageId, t.statusReportId),
+ }),
+);
+
+export const pagesToStatusReportsRelations = relations(
+ pagesToStatusReports,
+ ({ one }) => ({
+ page: one(page, {
+ fields: [pagesToStatusReports.pageId],
+ references: [page.id],
+ }),
+ statusReport: one(statusReport, {
+ fields: [pagesToStatusReports.statusReportId],
+ references: [statusReport.id],
+ }),
+ }),
+);
diff --git a/packages/db/src/schema/status_reports/validation.ts b/packages/db/src/schema/status_reports/validation.ts
new file mode 100644
index 000000000..f07ba54a9
--- /dev/null
+++ b/packages/db/src/schema/status_reports/validation.ts
@@ -0,0 +1,53 @@
+import { createInsertSchema, createSelectSchema } from "drizzle-zod";
+import * as z from "zod";
+
+import {
+ statusReport,
+ statusReportStatus,
+ statusReportUpdate,
+} from "./status_reports";
+
+export const statusReportStatusSchema = z.enum(statusReportStatus);
+
+export const insertStatusReportUpdateSchema = createInsertSchema(
+ statusReportUpdate,
+ {
+ status: statusReportStatusSchema,
+ },
+);
+
+export const insertStatusReportSchema = createInsertSchema(statusReport, {
+ status: statusReportStatusSchema,
+})
+ .extend({
+ date: z.date().optional().default(new Date()),
+ /**
+ * relationship to monitors and pages
+ */
+ monitors: z.number().array().optional().default([]),
+ pages: z.number().array().optional().default([]),
+ })
+ .extend({
+ /**
+ * message for the `InsertIncidentUpdate`
+ */
+ message: z.string(),
+ });
+
+export const selectStatusReportSchema = createSelectSchema(statusReport, {
+ status: statusReportStatusSchema,
+});
+
+export const selectStatusReportUpdateSchema = createSelectSchema(
+ statusReportUpdate,
+ {
+ status: statusReportStatusSchema,
+ },
+);
+
+export type InsertStatusReport = z.infer<typeof insertStatusReportSchema>;
+export type StatusReport = z.infer<typeof selectStatusReportSchema>;
+export type InsertStatusReportUpdate = z.infer<
+ typeof insertStatusReportUpdateSchema
+>;
+export type StatusReportUpdate = z.infer<typeof selectStatusReportUpdateSchema>;
diff --git a/packages/db/src/seed.mts b/packages/db/src/seed.mts
index 62b02a672..9739b93b5 100644
--- a/packages/db/src/seed.mts
+++ b/packages/db/src/seed.mts
@@ -5,13 +5,13 @@ import { drizzle } from "drizzle-orm/libsql";
import { env } from "../env.mjs";
import {
- incident,
- incidentUpdate,
monitor,
monitorsToPages,
notification,
notificationsToMonitors,
page,
+ statusReport,
+ statusReportUpdate,
user,
usersToWorkspaces,
workspace,
@@ -122,21 +122,21 @@ async function main() {
.run();
await db
- .insert(incident)
+ .insert(statusReport)
.values({
id: 1,
workspaceId: 1,
- title: "Test Incident",
+ title: "Test Status Report",
status: "investigating",
updatedAt: new Date(),
})
.run();
await db
- .insert(incidentUpdate)
+ .insert(statusReportUpdate)
.values({
id: 1,
- incidentId: 1,
+ statusReportId: 1,
status: "investigating",
message: "test",
date: new Date(),
diff --git a/packages/emails/index.ts b/packages/emails/index.ts
index d14fe453a..742fde6d5 100644
--- a/packages/emails/index.ts
+++ b/packages/emails/index.ts
@@ -18,7 +18,7 @@ export {
export const resend = new Resend(env.RESEND_API_KEY);
export interface Emails {
- react: ReactElement;
+ react: JSX.Element;
subject: "Welcome to OpenStatus.dev 👋";
to: string[];
from: "Thibault Le Ouay Ducasse <[email protected]>";
diff --git a/packages/tinybird/src/audit-log/base-validation.ts b/packages/tinybird/src/audit-log/base-validation.ts
index 06ad4210e..c449411e8 100644
--- a/packages/tinybird/src/audit-log/base-validation.ts
+++ b/packages/tinybird/src/audit-log/base-validation.ts
@@ -43,7 +43,8 @@ export const actorSchema = z
export const targetTypeSchema = z.enum([
"monitor",
"page",
- "incident",
+ // "incident", // has been removed from the schema
+ "status-report",
"user",
"notification",
"organization",