Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: page components [migration] (#1743)
Maximilian Kaske06d8d5363ea4
diff --git a/apps/server/src/routes/v1/__test__/sync.test.ts b/apps/server/src/routes/v1/__test__/sync.test.tsnew file mode 100644index 000000000..01b6bcb6e--- /dev/null+++ b/apps/server/src/routes/v1/__test__/sync.test.ts@@ -0,0 +1,576 @@+import { afterAll, beforeAll, describe, expect, test } from "bun:test";+import { and, db, eq, inArray } from "@openstatus/db";+import {+ maintenance,+ maintenancesToMonitors,+ maintenancesToPageComponents,+ monitor,+ monitorsToPages,+ monitorsToStatusReport,+ page,+ pageComponent,+ statusReport,+ statusReportUpdate,+ statusReportsToPageComponents,+} from "@openstatus/db/src/schema";++import { app } from "@/index";++/**+ * Sync Tests for REST API: Verify that mutations to legacy tables also sync to new page_component tables+ *+ * These tests use the REST API endpoints and verify that the sync operations+ * correctly update the new page_component related tables.+ */++const TEST_PREFIX = "api-sync-test";+let testPageId: number;+let testMonitorId: number;++beforeAll(async () => {+ // Clean up any existing test data+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.name, `${TEST_PREFIX}-monitor`));+ await db.delete(page).where(eq(page.slug, `${TEST_PREFIX}-page`));+ await db.delete(monitor).where(eq(monitor.name, `${TEST_PREFIX}-monitor`));++ // Create test page+ const testPage = await db+ .insert(page)+ .values({+ workspaceId: 1,+ title: "API Sync Test Page",+ description: "A test page for API sync tests",+ slug: `${TEST_PREFIX}-page`,+ customDomain: "",+ })+ .returning()+ .get();+ testPageId = testPage.id;++ // Create test monitor+ const testMonitor = await db+ .insert(monitor)+ .values({+ workspaceId: 1,+ name: `${TEST_PREFIX}-monitor`,+ url: "https://api-sync-test.example.com",+ periodicity: "1m",+ active: true,+ regions: "ams",+ jobType: "http",+ })+ .returning()+ .get();+ testMonitorId = testMonitor.id;++ // Add monitor to page (creates monitors_to_pages entry)+ await db.insert(monitorsToPages).values({+ monitorId: testMonitorId,+ pageId: testPageId,+ });++ // Create page_component for the monitor (simulating initial sync)+ await db+ .insert(pageComponent)+ .values({+ workspaceId: 1,+ pageId: testPageId,+ monitorId: testMonitorId,+ type: "monitor",+ name: `${TEST_PREFIX}-monitor`,+ })+ .onConflictDoNothing();+});++afterAll(async () => {+ // Clean up test data in correct order+ await db+ .delete(maintenancesToPageComponents)+ .where(+ inArray(+ maintenancesToPageComponents.pageComponentId,+ db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.pageId, testPageId)),+ ),+ );+ await db+ .delete(statusReportsToPageComponents)+ .where(+ inArray(+ statusReportsToPageComponents.pageComponentId,+ db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.pageId, testPageId)),+ ),+ );+ await db.delete(pageComponent).where(eq(pageComponent.pageId, testPageId));+ await db+ .delete(monitorsToPages)+ .where(eq(monitorsToPages.pageId, testPageId));+ await db+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.monitorId, testMonitorId));+ await db+ .delete(monitorsToStatusReport)+ .where(eq(monitorsToStatusReport.monitorId, testMonitorId));+ await db+ .delete(statusReportUpdate)+ .where(+ inArray(+ statusReportUpdate.statusReportId,+ db+ .select({ id: statusReport.id })+ .from(statusReport)+ .where(eq(statusReport.pageId, testPageId)),+ ),+ );+ await db.delete(statusReport).where(eq(statusReport.pageId, testPageId));+ await db.delete(maintenance).where(eq(maintenance.pageId, testPageId));+ await db.delete(page).where(eq(page.slug, `${TEST_PREFIX}-page`));+ await db.delete(monitor).where(eq(monitor.name, `${TEST_PREFIX}-monitor`));+});++describe("API Sync: POST /v1/maintenance - maintenance_to_page_component", () => {+ let createdMaintenanceId: number;++ afterAll(async () => {+ if (createdMaintenanceId) {+ await db+ .delete(maintenancesToPageComponents)+ .where(+ eq(maintenancesToPageComponents.maintenanceId, createdMaintenanceId),+ );+ await db+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.maintenanceId, createdMaintenanceId));+ await db+ .delete(maintenance)+ .where(eq(maintenance.id, createdMaintenanceId));+ }+ });++ test("creating maintenance with monitors syncs to maintenance_to_page_component", async () => {+ const from = new Date();+ const to = new Date(from.getTime() + 3600000);++ const res = await app.request("/v1/maintenance", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ title: `${TEST_PREFIX} Maintenance`,+ message: "Test maintenance for sync",+ from: from.toISOString(),+ to: to.toISOString(),+ monitorIds: [testMonitorId],+ pageId: testPageId,+ }),+ });++ expect(res.status).toBe(200);++ const data = await res.json();+ createdMaintenanceId = data.id;++ // Verify maintenance_to_monitor was created+ const maintenanceToMonitor =+ await db.query.maintenancesToMonitors.findFirst({+ where: and(+ eq(maintenancesToMonitors.maintenanceId, createdMaintenanceId),+ eq(maintenancesToMonitors.monitorId, testMonitorId),+ ),+ });+ expect(maintenanceToMonitor).toBeDefined();++ // Verify maintenance_to_page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });++ if (component) {+ const maintenanceToComponent =+ await db.query.maintenancesToPageComponents.findFirst({+ where: and(+ eq(+ maintenancesToPageComponents.maintenanceId,+ createdMaintenanceId,+ ),+ eq(maintenancesToPageComponents.pageComponentId, component.id),+ ),+ });+ expect(maintenanceToComponent).toBeDefined();+ }+ });+});++describe("API Sync: PUT /v1/maintenance - maintenance_to_page_component updates", () => {+ let testMaintenanceId: number;++ beforeAll(async () => {+ // Create a maintenance for update tests+ const from = new Date();+ const to = new Date(from.getTime() + 3600000);++ const newMaintenance = await db+ .insert(maintenance)+ .values({+ workspaceId: 1,+ pageId: testPageId,+ title: `${TEST_PREFIX} Update Test Maintenance`,+ message: "For update tests",+ from,+ to,+ })+ .returning()+ .get();+ testMaintenanceId = newMaintenance.id;++ // Add monitor to maintenance+ await db.insert(maintenancesToMonitors).values({+ maintenanceId: testMaintenanceId,+ monitorId: testMonitorId,+ });++ // Sync to page component+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });++ if (component) {+ await db+ .insert(maintenancesToPageComponents)+ .values({+ maintenanceId: testMaintenanceId,+ pageComponentId: component.id,+ })+ .onConflictDoNothing();+ }+ });++ afterAll(async () => {+ if (testMaintenanceId) {+ await db+ .delete(maintenancesToPageComponents)+ .where(+ eq(maintenancesToPageComponents.maintenanceId, testMaintenanceId),+ );+ await db+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.maintenanceId, testMaintenanceId));+ await db.delete(maintenance).where(eq(maintenance.id, testMaintenanceId));+ }+ });++ test("removing monitors from maintenance syncs delete to maintenance_to_page_component", async () => {+ const res = await app.request(`/v1/maintenance/${testMaintenanceId}`, {+ method: "PUT",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ monitorIds: [],+ }),+ });++ expect(res.status).toBe(200);++ // Verify maintenance_to_monitor was deleted+ const maintenanceToMonitor =+ await db.query.maintenancesToMonitors.findFirst({+ where: and(+ eq(maintenancesToMonitors.maintenanceId, testMaintenanceId),+ eq(maintenancesToMonitors.monitorId, testMonitorId),+ ),+ });+ expect(maintenanceToMonitor).toBeUndefined();++ // Verify maintenance_to_page_component was also deleted+ const maintenanceToComponent =+ await db.query.maintenancesToPageComponents.findFirst({+ where: eq(+ maintenancesToPageComponents.maintenanceId,+ testMaintenanceId,+ ),+ });+ expect(maintenanceToComponent).toBeUndefined();+ });+});++describe("API Sync: POST /v1/status_report - status_report_to_page_component", () => {+ let createdStatusReportId: number;++ afterAll(async () => {+ if (createdStatusReportId) {+ await db+ .delete(statusReportsToPageComponents)+ .where(+ eq(+ statusReportsToPageComponents.statusReportId,+ createdStatusReportId,+ ),+ );+ await db+ .delete(monitorsToStatusReport)+ .where(+ eq(monitorsToStatusReport.statusReportId, createdStatusReportId),+ );+ await db+ .delete(statusReportUpdate)+ .where(eq(statusReportUpdate.statusReportId, createdStatusReportId));+ await db+ .delete(statusReport)+ .where(eq(statusReport.id, createdStatusReportId));+ }+ });++ test("creating status report with monitors syncs to status_report_to_page_component", async () => {+ const res = await app.request("/v1/status_report", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ title: `${TEST_PREFIX} Status Report`,+ status: "investigating",+ message: "Test status report for sync",+ monitorIds: [testMonitorId],+ pageId: testPageId,+ }),+ });++ expect(res.status).toBe(200);++ const data = await res.json();+ createdStatusReportId = data.id;++ // Verify status_report_to_monitors was created+ const reportToMonitor = await db.query.monitorsToStatusReport.findFirst({+ where: and(+ eq(monitorsToStatusReport.statusReportId, createdStatusReportId),+ eq(monitorsToStatusReport.monitorId, testMonitorId),+ ),+ });+ expect(reportToMonitor).toBeDefined();++ // Verify status_report_to_page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });++ if (component) {+ const reportToComponent =+ await db.query.statusReportsToPageComponents.findFirst({+ where: and(+ eq(+ statusReportsToPageComponents.statusReportId,+ createdStatusReportId,+ ),+ eq(statusReportsToPageComponents.pageComponentId, component.id),+ ),+ });+ expect(reportToComponent).toBeDefined();+ }+ });+});++describe("API Sync: POST /v1/page - monitors_to_pages -> page_component", () => {+ let createdPageId: number;++ afterAll(async () => {+ if (createdPageId) {+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.pageId, createdPageId));+ await db+ .delete(monitorsToPages)+ .where(eq(monitorsToPages.pageId, createdPageId));+ await db.delete(page).where(eq(page.id, createdPageId));+ }+ });++ test("creating page with monitors syncs to page_component", async () => {+ const res = await app.request("/v1/page", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ title: `${TEST_PREFIX} New Page`,+ description: "Test page for sync",+ slug: `${TEST_PREFIX}-new-page`,+ monitors: [testMonitorId],+ }),+ });++ expect(res.status).toBe(200);++ const data = await res.json();+ createdPageId = data.id;++ // Verify monitors_to_pages was created+ const monitorToPage = await db.query.monitorsToPages.findFirst({+ where: and(+ eq(monitorsToPages.monitorId, testMonitorId),+ eq(monitorsToPages.pageId, createdPageId),+ ),+ });+ expect(monitorToPage).toBeDefined();++ // Verify page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, createdPageId),+ ),+ });+ expect(component).toBeDefined();+ expect(component?.type).toBe("monitor");+ });+});++describe("API Sync: PUT /v1/page - monitors_to_pages -> page_component updates", () => {+ let updateTestPageId: number;++ beforeAll(async () => {+ // Create a page for update tests+ const updateTestPage = await db+ .insert(page)+ .values({+ workspaceId: 1,+ title: `${TEST_PREFIX} Update Test Page`,+ description: "For update tests",+ slug: `${TEST_PREFIX}-update-page`,+ customDomain: "",+ })+ .returning()+ .get();+ updateTestPageId = updateTestPage.id;+ });++ afterAll(async () => {+ if (updateTestPageId) {+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.pageId, updateTestPageId));+ await db+ .delete(monitorsToPages)+ .where(eq(monitorsToPages.pageId, updateTestPageId));+ await db.delete(page).where(eq(page.id, updateTestPageId));+ }+ });++ test("adding monitors to page syncs to page_component", async () => {+ const res = await app.request(`/v1/page/${updateTestPageId}`, {+ method: "PUT",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ monitors: [testMonitorId],+ }),+ });++ expect(res.status).toBe(200);++ // Verify monitors_to_pages was created+ const monitorToPage = await db.query.monitorsToPages.findFirst({+ where: and(+ eq(monitorsToPages.monitorId, testMonitorId),+ eq(monitorsToPages.pageId, updateTestPageId),+ ),+ });+ expect(monitorToPage).toBeDefined();++ // Verify page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, updateTestPageId),+ ),+ });+ expect(component).toBeDefined();+ });++ test("removing monitors from page syncs delete to page_component", async () => {+ // First ensure monitor is on the page+ await db+ .insert(monitorsToPages)+ .values({+ monitorId: testMonitorId,+ pageId: updateTestPageId,+ })+ .onConflictDoNothing();++ await db+ .insert(pageComponent)+ .values({+ workspaceId: 1,+ pageId: updateTestPageId,+ monitorId: testMonitorId,+ type: "monitor",+ name: `${TEST_PREFIX}-monitor`,+ })+ .onConflictDoNothing();++ // Verify page_component exists before removal+ let component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, updateTestPageId),+ ),+ });+ expect(component).toBeDefined();++ // Remove all monitors+ const res = await app.request(`/v1/page/${updateTestPageId}`, {+ method: "PUT",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify({+ monitors: [],+ }),+ });++ expect(res.status).toBe(200);++ // Verify monitors_to_pages was deleted+ const monitorToPage = await db.query.monitorsToPages.findFirst({+ where: and(+ eq(monitorsToPages.monitorId, testMonitorId),+ eq(monitorsToPages.pageId, updateTestPageId),+ ),+ });+ expect(monitorToPage).toBeUndefined();++ // Verify page_component was deleted+ component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, updateTestPageId),+ ),+ });+ expect(component).toBeUndefined();+ });+});diff --git a/apps/server/src/routes/v1/maintenances/post.ts b/apps/server/src/routes/v1/maintenances/post.tsindex f7d3b22d3..85144457e 100644--- a/apps/server/src/routes/v1/maintenances/post.ts+++ b/apps/server/src/routes/v1/maintenances/post.ts@@ -3,7 +3,15 @@ import { OpenStatusApiError, openApiErrorResponses } from "@/libs/errors";import { trackMiddleware } from "@/libs/middlewares";import { createRoute } from "@hono/zod-openapi";import { Events } from "@openstatus/analytics";-import { and, db, eq, inArray, isNotNull, isNull } from "@openstatus/db";+import {+ and,+ db,+ eq,+ inArray,+ isNotNull,+ isNull,+ syncMaintenanceToMonitorInsertMany,+} from "@openstatus/db";import { monitor, page, pageSubscriber } from "@openstatus/db/src/schema";import {maintenance,@@ -110,6 +118,12 @@ export function registerPostMaintenance(api: typeof maintenancesApi) {})),).run();+ // Sync to page components+ await syncMaintenanceToMonitorInsertMany(+ tx,+ newMaintenance.id,+ input.monitorIds,+ );}return newMaintenance;diff --git a/apps/server/src/routes/v1/maintenances/put.ts b/apps/server/src/routes/v1/maintenances/put.tsindex 9c4ea7246..cbf36fc20 100644--- a/apps/server/src/routes/v1/maintenances/put.ts+++ b/apps/server/src/routes/v1/maintenances/put.ts@@ -2,7 +2,15 @@ import { OpenStatusApiError, openApiErrorResponses } from "@/libs/errors";import { trackMiddleware } from "@/libs/middlewares";import { createRoute } from "@hono/zod-openapi";import { Events } from "@openstatus/analytics";-import { and, db, eq, inArray, isNull } from "@openstatus/db";+import {+ and,+ db,+ eq,+ inArray,+ isNull,+ syncMaintenanceToMonitorDeleteByMaintenance,+ syncMaintenanceToMonitorInsertMany,+} from "@openstatus/db";import { monitor, page } from "@openstatus/db/src/schema";import {maintenance,@@ -128,6 +136,8 @@ export function registerPutMaintenance(api: typeof maintenancesApi) {.delete(maintenancesToMonitors).where(eq(maintenancesToMonitors.maintenanceId, Number(id))).run();+ // Sync delete to page components+ await syncMaintenanceToMonitorDeleteByMaintenance(tx, Number(id));// Add new monitor associationsif (monitorIds.length > 0) {@@ -140,6 +150,8 @@ export function registerPutMaintenance(api: typeof maintenancesApi) {})),).run();+ // Sync to page components+ await syncMaintenanceToMonitorInsertMany(tx, Number(id), monitorIds);}}diff --git a/apps/server/src/routes/v1/pages/post.ts b/apps/server/src/routes/v1/pages/post.tsindex e877278e3..9d73aeb15 100644--- a/apps/server/src/routes/v1/pages/post.ts+++ b/apps/server/src/routes/v1/pages/post.ts@@ -1,6 +1,13 @@import { createRoute } from "@hono/zod-openapi";-import { and, eq, inArray, isNull, sql } from "@openstatus/db";+import {+ and,+ eq,+ inArray,+ isNull,+ sql,+ syncMonitorsToPageInsert,+} from "@openstatus/db";import { db } from "@openstatus/db/src/db";import {monitor,@@ -182,6 +189,12 @@ export function registerPostPage(api: typeof pagesApi) {.insert(monitorsToPages).values({ pageId: _page.id, ...values }).run();+ // Sync to page components+ await syncMonitorsToPageInsert(db, {+ monitorId: values.monitorId,+ pageId: _page.id,+ order: "order" in values ? values.order : undefined,+ });}}const data = transformPageData(PageSchema.parse(_page));diff --git a/apps/server/src/routes/v1/pages/put.ts b/apps/server/src/routes/v1/pages/put.tsindex e9a1717a2..0359385a8 100644--- a/apps/server/src/routes/v1/pages/put.ts+++ b/apps/server/src/routes/v1/pages/put.ts@@ -3,7 +3,15 @@ import { createRoute } from "@hono/zod-openapi";import { OpenStatusApiError, openApiErrorResponses } from "@/libs/errors";import { trackMiddleware } from "@/libs/middlewares";import { Events } from "@openstatus/analytics";-import { and, eq, inArray, isNull, sql } from "@openstatus/db";+import {+ and,+ eq,+ inArray,+ isNull,+ sql,+ syncMonitorsToPageDelete,+ syncMonitorsToPageInsert,+} from "@openstatus/db";import { db } from "@openstatus/db/src/db";import {monitor,@@ -194,6 +202,10 @@ export function registerPutPage(api: typeof pagesApi) {eq(monitorsToPages.pageId, newPage.id),),);+ // Sync delete to page components+ for (const monitorId of removedMonitors) {+ await syncMonitorsToPageDelete(db, { monitorId, pageId: newPage.id });+ }}if (monitors) {@@ -208,6 +220,12 @@ export function registerPutPage(api: typeof pagesApi) {target: [monitorsToPages.monitorId, monitorsToPages.pageId],set: { order: sql.raw("excluded.`order`") },});+ // Sync to page components (existing ones will be ignored due to onConflictDoNothing in sync)+ await syncMonitorsToPageInsert(db, {+ monitorId: values.monitorId,+ pageId: newPage.id,+ order: "order" in values ? values.order : undefined,+ });}}diff --git a/apps/server/src/routes/v1/statusReports/post.ts b/apps/server/src/routes/v1/statusReports/post.tsindex b80837724..4a97ba8fc 100644--- a/apps/server/src/routes/v1/statusReports/post.ts+++ b/apps/server/src/routes/v1/statusReports/post.ts@@ -1,6 +1,14 @@import { createRoute, z } from "@hono/zod-openapi";-import { and, db, eq, inArray, isNotNull, isNull } from "@openstatus/db";+import {+ and,+ db,+ eq,+ inArray,+ isNotNull,+ isNull,+ syncStatusReportToMonitorInsertMany,+} from "@openstatus/db";import {monitor,monitorsToStatusReport,@@ -133,6 +141,12 @@ export function registerPostStatusReport(api: typeof statusReportsApi) {}),).returning();+ // Sync to page components+ await syncStatusReportToMonitorInsertMany(+ db,+ _newStatusReport.id,+ input.monitorIds,+ );}if (limits["status-subscribers"] && _newStatusReport.pageId) {diff --git a/packages/api/src/router/maintenance.ts b/packages/api/src/router/maintenance.tsindex c7e7ad391..ab82a5b2b 100644--- a/packages/api/src/router/maintenance.ts+++ b/packages/api/src/router/maintenance.ts@@ -9,6 +9,8 @@ import {gte,inArray,lte,+ syncMaintenanceToMonitorDeleteByMaintenance,+ syncMaintenanceToMonitorInsertMany,} from "@openstatus/db";import {maintenance,@@ -217,6 +219,12 @@ export const maintenanceRouter = createTRPCRouter({monitorId,})),);+ // Sync to page components+ await syncMaintenanceToMonitorInsertMany(+ tx,+ newMaintenance.id,+ opts.input.monitors,+ );}return newMaintenance;@@ -287,6 +295,8 @@ export const maintenanceRouter = createTRPCRouter({.delete(maintenancesToMonitors).where(eq(maintenancesToMonitors.maintenanceId, _maintenance.id)).run();+ // Sync delete to page components+ await syncMaintenanceToMonitorDeleteByMaintenance(tx, _maintenance.id);// Create new relations if monitors are providedif (opts.input.monitors?.length) {@@ -296,6 +306,12 @@ export const maintenanceRouter = createTRPCRouter({monitorId,})),);+ // Sync to page components+ await syncMaintenanceToMonitorInsertMany(+ tx,+ _maintenance.id,+ opts.input.monitors,+ );}return _maintenance;diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.tsindex 842e889df..73b53d6b7 100644--- a/packages/api/src/router/monitor.ts+++ b/packages/api/src/router/monitor.ts@@ -14,7 +14,20 @@ import {statusAssertion,textBodyAssertion,} from "@openstatus/assertions";-import { type SQL, and, count, eq, inArray, isNull, sql } from "@openstatus/db";+import {+ type SQL,+ and,+ count,+ eq,+ inArray,+ isNull,+ sql,+ syncMaintenanceToMonitorDeleteByMonitors,+ syncMonitorsToPageDelete,+ syncMonitorsToPageDeleteByMonitors,+ syncMonitorsToPageInsertMany,+ syncStatusReportToMonitorDeleteByMonitors,+} from "@openstatus/db";import {insertMonitorSchema,maintenancesToMonitors,@@ -187,6 +200,8 @@ export const monitorRouter = createTRPCRouter({}));await opts.ctx.db.insert(monitorsToPages).values(values).run();+ // Sync to page components+ await syncMonitorsToPageInsertMany(opts.ctx.db, values);}return selectMonitorSchema.parse(newMonitor);@@ -460,6 +475,8 @@ export const monitorRouter = createTRPCRouter({}));await opts.ctx.db.insert(monitorsToPages).values(values).run();+ // Sync to page components+ await syncMonitorsToPageInsertMany(opts.ctx.db, values);}const removedPages = currentMonitorPages@@ -476,6 +493,13 @@ export const monitorRouter = createTRPCRouter({),).run();+ // Sync delete to page components+ for (const pageId of removedPages) {+ await syncMonitorsToPageDelete(opts.ctx.db, {+ monitorId: currentMonitor.id,+ pageId,+ });+ }}}),@@ -593,6 +617,14 @@ export const monitorRouter = createTRPCRouter({await tx.delete(maintenancesToMonitors).where(eq(maintenancesToMonitors.monitorId, monitorToDelete.id));+ // Sync deletes to page components+ await syncMonitorsToPageDeleteByMonitors(tx, [monitorToDelete.id]);+ await syncStatusReportToMonitorDeleteByMonitors(tx, [+ monitorToDelete.id,+ ]);+ await syncMaintenanceToMonitorDeleteByMonitors(tx, [+ monitorToDelete.id,+ ]);});}),@@ -639,6 +671,10 @@ export const monitorRouter = createTRPCRouter({await tx.delete(maintenancesToMonitors).where(inArray(maintenancesToMonitors.monitorId, opts.input.ids));+ // Sync deletes to page components+ await syncMonitorsToPageDeleteByMonitors(tx, opts.input.ids);+ await syncStatusReportToMonitorDeleteByMonitors(tx, opts.input.ids);+ await syncMaintenanceToMonitorDeleteByMonitors(tx, opts.input.ids);});}),@@ -1250,15 +1286,20 @@ export const monitorRouter = createTRPCRouter({inArray(monitorsToPages.pageId, pageIdsToDelete),),);+ // Sync delete to page components+ for (const pageId of pageIdsToDelete) {+ await syncMonitorsToPageDelete(tx, { monitorId: input.id, pageId });+ }}if (pageIdsToInsert.length > 0) {- await tx.insert(monitorsToPages).values(- pageIdsToInsert.map((pageId) => ({- monitorId: input.id,- pageId,- })),- );+ const values = pageIdsToInsert.map((pageId) => ({+ monitorId: input.id,+ pageId,+ }));+ await tx.insert(monitorsToPages).values(values);+ // Sync to page components+ await syncMonitorsToPageInsertMany(tx, values);}await txdiff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.tsindex c37177459..67feecf38 100644--- a/packages/api/src/router/page.ts+++ b/packages/api/src/router/page.ts@@ -11,6 +11,11 @@ import {isNull,lte,sql,+ syncMonitorGroupDeleteMany,+ syncMonitorGroupInsert,+ syncMonitorsToPageDelete,+ syncMonitorsToPageDeleteByPage,+ syncMonitorsToPageInsertMany,} from "@openstatus/db";import {incidentTable,@@ -142,6 +147,8 @@ export const pageRouter = createTRPCRouter({}));await opts.ctx.db.insert(monitorsToPages).values(values).run();+ // Sync to page components+ await syncMonitorsToPageInsertMany(opts.ctx.db, values);}return newPage;@@ -241,6 +248,13 @@ export const pageRouter = createTRPCRouter({eq(monitorsToPages.pageId, currentPage.id),),);+ // Sync delete to page components+ for (const monitorId of removedMonitors) {+ await syncMonitorsToPageDelete(opts.ctx.db, {+ monitorId,+ pageId: currentPage.id,+ });+ }}const values = monitors.map(({ monitorId }, index) => ({@@ -257,6 +271,8 @@ export const pageRouter = createTRPCRouter({target: [monitorsToPages.monitorId, monitorsToPages.pageId],set: { order: sql.raw("excluded.`order`") },});+ // Sync new monitors to page components (existing ones will be ignored due to onConflictDoNothing)+ await syncMonitorsToPageInsertMany(opts.ctx.db, values);}}),delete: protectedProcedure@@ -947,6 +963,12 @@ export const pageRouter = createTRPCRouter({}await opts.ctx.db.transaction(async (tx) => {+ // Get existing monitor groups to delete from page components+ const existingGroups = await tx.query.monitorGroup.findMany({+ where: eq(monitorGroup.pageId, opts.input.id),+ });+ const existingGroupIds = existingGroups.map((g) => g.id);+// Delete child records first to avoid foreign key constraint violationawait tx.delete(monitorsToPages)@@ -955,6 +977,12 @@ export const pageRouter = createTRPCRouter({.delete(monitorGroup).where(eq(monitorGroup.pageId, opts.input.id));+ // Sync deletes to page components+ await syncMonitorsToPageDeleteByPage(tx, opts.input.id);+ if (existingGroupIds.length > 0) {+ await syncMonitorGroupDeleteMany(tx, existingGroupIds);+ }+if (opts.input.groups.length > 0) {const monitorGroups = await tx.insert(monitorGroup)@@ -967,27 +995,41 @@ export const pageRouter = createTRPCRouter({).returning();- await tx.insert(monitorsToPages).values(- opts.input.groups.flatMap((g, i) =>- g.monitors.map((m) => ({- pageId: opts.input.id,- monitorId: m.id,- order: g.order,- monitorGroupId: monitorGroups[i].id,- groupOrder: m.order,- })),- ),- );- }+ // Sync new monitor groups to page component groups+ for (const group of monitorGroups) {+ await syncMonitorGroupInsert(tx, {+ id: group.id,+ workspaceId: opts.ctx.workspace.id,+ pageId: opts.input.id,+ name: group.name,+ });+ }- if (opts.input.monitors.length > 0) {- await tx.insert(monitorsToPages).values(- opts.input.monitors.map((m) => ({+ const groupMonitorValues = opts.input.groups.flatMap((g, i) =>+ g.monitors.map((m) => ({pageId: opts.input.id,monitorId: m.id,- order: m.order,+ order: g.order,+ monitorGroupId: monitorGroups[i].id,+ groupOrder: m.order,})),);++ await tx.insert(monitorsToPages).values(groupMonitorValues);+ // Sync to page components+ await syncMonitorsToPageInsertMany(tx, groupMonitorValues);+ }++ if (opts.input.monitors.length > 0) {+ const monitorValues = opts.input.monitors.map((m) => ({+ pageId: opts.input.id,+ monitorId: m.id,+ order: m.order,+ }));++ await tx.insert(monitorsToPages).values(monitorValues);+ // Sync to page components+ await syncMonitorsToPageInsertMany(tx, monitorValues);}});}),diff --git a/packages/api/src/router/statusReport.ts b/packages/api/src/router/statusReport.tsindex 952df7f10..e7d543793 100644--- a/packages/api/src/router/statusReport.ts+++ b/packages/api/src/router/statusReport.ts@@ -9,6 +9,8 @@ import {gte,inArray,sql,+ syncStatusReportToMonitorDeleteByStatusReport,+ syncStatusReportToMonitorInsertMany,} from "@openstatus/db";import {insertStatusReportSchema,@@ -57,6 +59,12 @@ export const statusReportRouter = createTRPCRouter({).returning().get();+ // Sync to page components+ await syncStatusReportToMonitorInsertMany(+ opts.ctx.db,+ newStatusReport.id,+ monitors,+ );}return newStatusReport;@@ -143,6 +151,12 @@ export const statusReportRouter = createTRPCRouter({}));await opts.ctx.db.insert(monitorsToStatusReport).values(values).run();+ // Sync to page components+ await syncStatusReportToMonitorInsertMany(+ opts.ctx.db,+ currentStatusReport.id,+ addedMonitors,+ );}const removedMonitors = currentMonitorsToStatusReport@@ -159,6 +173,7 @@ export const statusReportRouter = createTRPCRouter({),).run();+ // Sync delete is handled by cascade on page_component deletion}return currentStatusReport;@@ -476,6 +491,12 @@ export const statusReportRouter = createTRPCRouter({).returning().get();+ // Sync to page components+ await syncStatusReportToMonitorInsertMany(+ tx,+ newStatusReport.id,+ opts.input.monitors,+ );}return {@@ -516,6 +537,8 @@ export const statusReportRouter = createTRPCRouter({.delete(monitorsToStatusReport).where(eq(monitorsToStatusReport.statusReportId, opts.input.id)).run();+ // Sync delete to page components+ await syncStatusReportToMonitorDeleteByStatusReport(tx, opts.input.id);if (opts.input.monitors.length > 0) {await tx@@ -527,6 +550,12 @@ export const statusReportRouter = createTRPCRouter({})),).run();+ // Sync to page components+ await syncStatusReportToMonitorInsertMany(+ tx,+ opts.input.id,+ opts.input.monitors,+ );}});}),diff --git a/packages/api/src/router/sync.test.ts b/packages/api/src/router/sync.test.tsnew file mode 100644index 000000000..d6766de04--- /dev/null+++ b/packages/api/src/router/sync.test.ts@@ -0,0 +1,608 @@+import { afterAll, beforeAll, describe, expect, test } from "bun:test";+import { and, db, eq, inArray } from "@openstatus/db";+import {+ maintenance,+ maintenancesToMonitors,+ maintenancesToPageComponents,+ monitor,+ monitorGroup,+ monitorsToPages,+ monitorsToStatusReport,+ page,+ pageComponent,+ pageComponentGroup,+ statusReport,+ statusReportUpdate,+ statusReportsToPageComponents,+} from "@openstatus/db/src/schema";+import { flyRegions } from "@openstatus/db/src/schema/constants";++import { appRouter } from "../root";+import { createInnerTRPCContext } from "../trpc";++/**+ * Sync Tests: Verify that mutations to legacy tables also sync to new page_component tables+ *+ * Table mappings:+ * - monitor_group -> page_component_groups+ * - monitors_to_pages -> page_component+ * - status_report_to_monitors -> status_report_to_page_component+ * - maintenance_to_monitor -> maintenance_to_page_component+ */++function getTestContext(limits?: unknown) {+ return createInnerTRPCContext({+ req: undefined,+ session: {+ user: {+ id: "1",+ },+ },+ workspace: {+ id: 1,+ // @ts-expect-error - test context with partial limits+ limits: limits || {+ monitors: 100,+ periodicity: ["30s", "1m", "5m", "10m", "30m", "1h"],+ regions: flyRegions,+ "status-pages": 10,+ maintenance: true,+ notifications: 10,+ "status-subscribers": true,+ sms: false,+ pagerduty: true,+ "password-protection": true,+ "email-domain-protection": true,+ "custom-domain": true,+ },+ },+ });+}++// Test data identifiers+const TEST_PREFIX = "sync-test";+let testPageId: number;+let testMonitorId: number;++const monitorData = {+ name: `${TEST_PREFIX}-monitor`,+ url: "https://sync-test.example.com",+ jobType: "http" as const,+ method: "GET" as const,+ periodicity: "1m" as const,+ regions: [flyRegions[0]],+ statusAssertions: [],+ headerAssertions: [],+ textBodyAssertions: [],+ notifications: [],+ pages: [] as number[],+ tags: [],+};++beforeAll(async () => {+ // Clean up any existing test data+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.name, `${TEST_PREFIX}-monitor`));+ await db.delete(page).where(eq(page.slug, `${TEST_PREFIX}-page`));+ await db.delete(monitor).where(eq(monitor.name, `${TEST_PREFIX}-monitor`));+ await db+ .delete(monitor)+ .where(eq(monitor.name, `${TEST_PREFIX}-deletable-monitor`));++ // Create test page first+ const testPage = await db+ .insert(page)+ .values({+ workspaceId: 1,+ title: "Sync Test Page",+ description: "A test page for sync tests",+ slug: `${TEST_PREFIX}-page`,+ customDomain: "",+ })+ .returning()+ .get();+ testPageId = testPage.id;++ // Create test monitor using tRPC+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);+ const createdMonitor = await caller.monitor.create(monitorData);+ testMonitorId = createdMonitor.id;+});++afterAll(async () => {+ // Clean up test data in correct order (dependencies first)+ await db+ .delete(maintenancesToPageComponents)+ .where(+ inArray(+ maintenancesToPageComponents.pageComponentId,+ db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.pageId, testPageId)),+ ),+ );+ await db+ .delete(statusReportsToPageComponents)+ .where(+ inArray(+ statusReportsToPageComponents.pageComponentId,+ db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.pageId, testPageId)),+ ),+ );+ await db.delete(pageComponent).where(eq(pageComponent.pageId, testPageId));+ await db+ .delete(pageComponentGroup)+ .where(eq(pageComponentGroup.pageId, testPageId));+ await db.delete(monitorGroup).where(eq(monitorGroup.pageId, testPageId));+ await db+ .delete(monitorsToPages)+ .where(eq(monitorsToPages.pageId, testPageId));+ await db+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.monitorId, testMonitorId));+ await db+ .delete(monitorsToStatusReport)+ .where(eq(monitorsToStatusReport.monitorId, testMonitorId));+ await db+ .delete(statusReportUpdate)+ .where(+ inArray(+ statusReportUpdate.statusReportId,+ db+ .select({ id: statusReport.id })+ .from(statusReport)+ .where(eq(statusReport.pageId, testPageId)),+ ),+ );+ await db.delete(statusReport).where(eq(statusReport.pageId, testPageId));+ await db.delete(maintenance).where(eq(maintenance.pageId, testPageId));+ await db.delete(page).where(eq(page.slug, `${TEST_PREFIX}-page`));+ await db.delete(monitor).where(eq(monitor.name, `${TEST_PREFIX}-monitor`));+ await db+ .delete(monitor)+ .where(eq(monitor.name, `${TEST_PREFIX}-deletable-monitor`));+});++describe("Sync: monitors_to_pages -> page_component", () => {+ test("Creating monitor-to-page relation syncs to page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Update monitor to add it to the test page+ await caller.monitor.update({+ ...monitorData,+ id: testMonitorId,+ pages: [testPageId],+ });++ // Verify monitors_to_pages was created+ const monitorToPage = await db.query.monitorsToPages.findFirst({+ where: and(+ eq(monitorsToPages.monitorId, testMonitorId),+ eq(monitorsToPages.pageId, testPageId),+ ),+ });+ expect(monitorToPage).toBeDefined();++ // Verify page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });+ expect(component).toBeDefined();+ expect(component?.type).toBe("monitor");+ expect(component?.workspaceId).toBe(1);+ });++ test("Removing monitor-to-page relation syncs delete to page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // First add the monitor to page if not already+ await caller.monitor.update({+ ...monitorData,+ id: testMonitorId,+ pages: [testPageId],+ });++ // Verify page_component exists+ let component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });+ expect(component).toBeDefined();++ // Remove monitor from page+ await caller.monitor.update({+ ...monitorData,+ id: testMonitorId,+ pages: [],+ });++ // Verify page_component was deleted+ component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });+ expect(component).toBeUndefined();+ });+});++describe("Sync: page.updateMonitors -> page_component and page_component_groups", () => {+ test("Adding monitors with groups syncs to page_component and page_component_groups", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Update page with monitor in a group+ await caller.page.updateMonitors({+ id: testPageId,+ monitors: [],+ groups: [+ {+ name: `${TEST_PREFIX}-group`,+ order: 0,+ monitors: [{ id: testMonitorId, order: 0 }],+ },+ ],+ });++ // Verify monitor_group was created+ const group = await db.query.monitorGroup.findFirst({+ where: and(+ eq(monitorGroup.pageId, testPageId),+ eq(monitorGroup.name, `${TEST_PREFIX}-group`),+ ),+ });+ expect(group).toBeDefined();++ if (!group) {+ throw new Error("Group not found");+ }++ // Verify page_component_groups was synced+ const componentGroup = await db.query.pageComponentGroup.findFirst({+ where: eq(pageComponentGroup.id, group.id),+ });+ expect(componentGroup).toBeDefined();+ expect(componentGroup?.name).toBe(`${TEST_PREFIX}-group`);+ expect(componentGroup?.pageId).toBe(testPageId);++ // Verify page_component was synced with group reference+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });+ expect(component).toBeDefined();+ expect(component?.groupId).toBe(group.id);+ });++ test("Updating page monitors syncs changes to page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // First, set up with a group+ await caller.page.updateMonitors({+ id: testPageId,+ monitors: [],+ groups: [+ {+ name: `${TEST_PREFIX}-group`,+ order: 0,+ monitors: [{ id: testMonitorId, order: 0 }],+ },+ ],+ });++ // Now update to remove the group and add monitor directly+ await caller.page.updateMonitors({+ id: testPageId,+ monitors: [{ id: testMonitorId, order: 0 }],+ groups: [],+ });++ // Verify monitor_group was deleted+ const group = await db.query.monitorGroup.findFirst({+ where: and(+ eq(monitorGroup.pageId, testPageId),+ eq(monitorGroup.name, `${TEST_PREFIX}-group`),+ ),+ });+ expect(group).toBeUndefined();++ // Verify page_component still exists but without group+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });+ expect(component).toBeDefined();+ expect(component?.groupId).toBeNull();+ });+});++describe("Sync: maintenance_to_monitor -> maintenance_to_page_component", () => {+ let testMaintenanceId: number;++ beforeAll(async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Ensure monitor is on the page first+ await caller.monitor.update({+ ...monitorData,+ id: testMonitorId,+ pages: [testPageId],+ });+ });++ afterAll(async () => {+ if (testMaintenanceId) {+ await db+ .delete(maintenancesToPageComponents)+ .where(+ eq(maintenancesToPageComponents.maintenanceId, testMaintenanceId),+ );+ await db+ .delete(maintenancesToMonitors)+ .where(eq(maintenancesToMonitors.maintenanceId, testMaintenanceId));+ await db.delete(maintenance).where(eq(maintenance.id, testMaintenanceId));+ }+ });++ test("Creating maintenance with monitors syncs to maintenance_to_page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ const from = new Date();+ const to = new Date(from.getTime() + 1000 * 60 * 60);++ const createdMaintenance = await caller.maintenance.new({+ title: `${TEST_PREFIX} Maintenance`,+ message: "Test maintenance for sync",+ startDate: from,+ endDate: to,+ pageId: testPageId,+ monitors: [testMonitorId],+ });+ testMaintenanceId = createdMaintenance.id;++ // Verify maintenance_to_monitor was created+ const maintenanceToMonitor =+ await db.query.maintenancesToMonitors.findFirst({+ where: and(+ eq(maintenancesToMonitors.maintenanceId, testMaintenanceId),+ eq(maintenancesToMonitors.monitorId, testMonitorId),+ ),+ });+ expect(maintenanceToMonitor).toBeDefined();++ // Verify maintenance_to_page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });++ if (component) {+ const maintenanceToComponent =+ await db.query.maintenancesToPageComponents.findFirst({+ where: and(+ eq(maintenancesToPageComponents.maintenanceId, testMaintenanceId),+ eq(maintenancesToPageComponents.pageComponentId, component.id),+ ),+ });+ expect(maintenanceToComponent).toBeDefined();+ }+ });++ test("Updating maintenance monitors syncs to maintenance_to_page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Skip if no maintenance was created+ if (!testMaintenanceId) return;++ const from = new Date();+ const to = new Date(from.getTime() + 1000 * 60 * 60);++ // Update maintenance to remove monitors+ await caller.maintenance.update({+ id: testMaintenanceId,+ title: `${TEST_PREFIX} Maintenance`,+ message: "Updated maintenance",+ startDate: from,+ endDate: to,+ monitors: [],+ });++ // Verify maintenance_to_monitor was deleted+ const maintenanceToMonitor =+ await db.query.maintenancesToMonitors.findFirst({+ where: and(+ eq(maintenancesToMonitors.maintenanceId, testMaintenanceId),+ eq(maintenancesToMonitors.monitorId, testMonitorId),+ ),+ });+ expect(maintenanceToMonitor).toBeUndefined();++ // Verify maintenance_to_page_component was also deleted+ const maintenanceToComponent =+ await db.query.maintenancesToPageComponents.findFirst({+ where: eq(+ maintenancesToPageComponents.maintenanceId,+ testMaintenanceId,+ ),+ });+ expect(maintenanceToComponent).toBeUndefined();+ });+});++describe("Sync: status_report_to_monitors -> status_report_to_page_component", () => {+ let testStatusReportId: number;++ beforeAll(async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Ensure monitor is on the page first+ await caller.monitor.update({+ ...monitorData,+ id: testMonitorId,+ pages: [testPageId],+ });+ });++ afterAll(async () => {+ if (testStatusReportId) {+ await db+ .delete(statusReportsToPageComponents)+ .where(+ eq(statusReportsToPageComponents.statusReportId, testStatusReportId),+ );+ await db+ .delete(monitorsToStatusReport)+ .where(eq(monitorsToStatusReport.statusReportId, testStatusReportId));+ await db+ .delete(statusReportUpdate)+ .where(eq(statusReportUpdate.statusReportId, testStatusReportId));+ await db+ .delete(statusReport)+ .where(eq(statusReport.id, testStatusReportId));+ }+ });++ test("Creating status report with monitors syncs to status_report_to_page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ const createdReport = await caller.statusReport.create({+ title: `${TEST_PREFIX} Status Report`,+ status: "investigating",+ message: "Test status report for sync",+ pageId: testPageId,+ monitors: [testMonitorId],+ date: new Date(),+ });+ testStatusReportId = createdReport.statusReportId;++ // Verify status_report_to_monitors was created+ const reportToMonitor = await db.query.monitorsToStatusReport.findFirst({+ where: and(+ eq(monitorsToStatusReport.statusReportId, testStatusReportId),+ eq(monitorsToStatusReport.monitorId, testMonitorId),+ ),+ });+ expect(reportToMonitor).toBeDefined();++ // Verify status_report_to_page_component was synced+ const component = await db.query.pageComponent.findFirst({+ where: and(+ eq(pageComponent.monitorId, testMonitorId),+ eq(pageComponent.pageId, testPageId),+ ),+ });++ if (component) {+ const reportToComponent =+ await db.query.statusReportsToPageComponents.findFirst({+ where: and(+ eq(+ statusReportsToPageComponents.statusReportId,+ testStatusReportId,+ ),+ eq(statusReportsToPageComponents.pageComponentId, component.id),+ ),+ });+ expect(reportToComponent).toBeDefined();+ }+ });++ test("Updating status report monitors syncs to status_report_to_page_component", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Skip if no status report was created+ if (!testStatusReportId) return;++ // Update status to remove monitors (using updateStatus procedure)+ await caller.statusReport.updateStatus({+ id: testStatusReportId,+ status: "resolved",+ monitors: [],+ title: `${TEST_PREFIX} Status Report`,+ });++ // Verify status_report_to_monitors was deleted+ const reportToMonitor = await db.query.monitorsToStatusReport.findFirst({+ where: and(+ eq(monitorsToStatusReport.statusReportId, testStatusReportId),+ eq(monitorsToStatusReport.monitorId, testMonitorId),+ ),+ });+ expect(reportToMonitor).toBeUndefined();++ // Verify status_report_to_page_component was also deleted+ const reportToComponent =+ await db.query.statusReportsToPageComponents.findFirst({+ where: eq(+ statusReportsToPageComponents.statusReportId,+ testStatusReportId,+ ),+ });+ expect(reportToComponent).toBeUndefined();+ });+});++describe("Sync: monitor deletion cascades to page_component tables", () => {+ let deletableMonitorId: number;++ beforeAll(async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Create a monitor specifically for deletion tests+ const deletableMonitor = await caller.monitor.create({+ ...monitorData,+ name: `${TEST_PREFIX}-deletable-monitor`,+ url: "https://delete-test.example.com",+ pages: [testPageId],+ });+ deletableMonitorId = deletableMonitor.id;+ });++ test("Deleting monitor removes related page_component entries", async () => {+ const ctx = getTestContext();+ const caller = appRouter.createCaller(ctx);++ // Verify page_component exists before deletion+ let component = await db.query.pageComponent.findFirst({+ where: eq(pageComponent.monitorId, deletableMonitorId),+ });+ expect(component).toBeDefined();++ // Delete the monitor+ await caller.monitor.delete({ id: deletableMonitorId });++ // Verify page_component was removed+ component = await db.query.pageComponent.findFirst({+ where: eq(pageComponent.monitorId, deletableMonitorId),+ });+ expect(component).toBeUndefined();+ });+});diff --git a/packages/db/drizzle/0054_bitter_lilandra.sql b/packages/db/drizzle/0054_bitter_lilandra.sqlnew file mode 100644index 000000000..172a240e8--- /dev/null+++ b/packages/db/drizzle/0054_bitter_lilandra.sql@@ -0,0 +1,127 @@+CREATE TABLE `maintenance_to_page_component` (+ `maintenance_id` integer NOT NULL,+ `page_component_id` integer NOT NULL,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ PRIMARY KEY(`maintenance_id`, `page_component_id`),+ FOREIGN KEY (`maintenance_id`) REFERENCES `maintenance`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`page_component_id`) REFERENCES `page_component`(`id`) ON UPDATE no action ON DELETE cascade+);+--> statement-breakpoint+CREATE TABLE `page_component` (+ `id` integer PRIMARY KEY NOT NULL,+ `workspace_id` integer NOT NULL,+ `page_id` integer NOT NULL,+ `type` text DEFAULT 'monitor' NOT NULL,+ `monitor_id` integer,+ `name` text NOT NULL,+ `description` text,+ `order` integer DEFAULT 0,+ `group_id` integer,+ `group_order` integer DEFAULT 0,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ `updated_at` integer DEFAULT (strftime('%s', 'now')),+ FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`page_id`) REFERENCES `page`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`monitor_id`) REFERENCES `monitor`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`group_id`) REFERENCES `page_component_groups`(`id`) ON UPDATE no action ON DELETE set null,+ CONSTRAINT "page_component_type_check" CHECK("page_component"."type" = 'monitor' AND "page_component"."monitor_id" IS NOT NULL OR "page_component"."type" = 'external' AND "page_component"."monitor_id" IS NULL)+);+--> statement-breakpoint+CREATE UNIQUE INDEX `page_component_page_id_monitor_id_unique` ON `page_component` (`page_id`,`monitor_id`);--> statement-breakpoint+CREATE TABLE `status_report_to_page_component` (+ `status_report_id` integer NOT NULL,+ `page_component_id` integer NOT NULL,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ PRIMARY KEY(`status_report_id`, `page_component_id`),+ FOREIGN KEY (`status_report_id`) REFERENCES `status_report`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`page_component_id`) REFERENCES `page_component`(`id`) ON UPDATE no action ON DELETE cascade+);+--> statement-breakpoint+CREATE TABLE `page_component_groups` (+ `id` integer PRIMARY KEY NOT NULL,+ `workspace_id` integer NOT NULL,+ `page_id` integer NOT NULL,+ `name` text NOT NULL,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ `updated_at` integer DEFAULT (strftime('%s', 'now')),+ FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`page_id`) REFERENCES `page`(`id`) ON UPDATE no action ON DELETE cascade+);+--> statement-breakpoint+-- Data Migration: monitors_to_pages → page_component+-- This section migrates data from the old structure to the new page_component structure+-- Step 0: Migrate monitor_group to page_component_groups+INSERT OR IGNORE INTO `page_component_groups` (+ `id`,+ `workspace_id`,+ `page_id`,+ `name`,+ `created_at`,+ `updated_at`+)+SELECT+ mg.id,+ mg.workspace_id,+ mg.page_id,+ mg.name,+ mg.created_at,+ mg.updated_at+FROM `monitor_group` mg;+--> statement-breakpoint+-- Step 1: Migrate monitors_to_pages to page_component+INSERT OR IGNORE INTO `page_component` (+ `workspace_id`,+ `page_id`,+ `type`,+ `monitor_id`,+ `name`,+ `order`,+ `group_id`,+ `group_order`,+ `created_at`,+ `updated_at`+)+SELECT+ m.workspace_id,+ mtp.page_id,+ 'monitor' as type,+ mtp.monitor_id,+ COALESCE(m.external_name, m.name, 'Unnamed Monitor') as name,+ COALESCE(mtp.`order`, 0),+ mtp.monitor_group_id as group_id,+ COALESCE(mtp.group_order, 0) as group_order,+ mtp.created_at,+ strftime('%s', 'now') as updated_at+FROM `monitors_to_pages` mtp+INNER JOIN `monitor` m ON mtp.monitor_id = m.id+WHERE m.workspace_id IS NOT NULL;+--> statement-breakpoint+-- Step 2: Migrate status_report_to_monitors to status_report_to_page_component+INSERT OR IGNORE INTO `status_report_to_page_component` (+ `status_report_id`,+ `page_component_id`,+ `created_at`+)+SELECT DISTINCT+ srtm.status_report_id,+ pc.id as page_component_id,+ srtm.created_at+FROM `status_report_to_monitors` srtm+INNER JOIN `status_report` sr ON srtm.status_report_id = sr.id+INNER JOIN `page_component` pc ON srtm.monitor_id = pc.monitor_id+WHERE (sr.page_id = pc.page_id OR sr.page_id IS NULL);+--> statement-breakpoint+-- Step 3: Migrate maintenance_to_monitor to maintenance_to_page_component+INSERT OR IGNORE INTO `maintenance_to_page_component` (+ `maintenance_id`,+ `page_component_id`,+ `created_at`+)+SELECT DISTINCT+ mtm.maintenance_id,+ pc.id as page_component_id,+ mtm.created_at+FROM `maintenance_to_monitor` mtm+INNER JOIN `maintenance` m ON mtm.maintenance_id = m.id+INNER JOIN `page_component` pc ON mtm.monitor_id = pc.monitor_id+WHERE (m.page_id = pc.page_id OR m.page_id IS NULL);\ No newline at end of filediff --git a/packages/db/drizzle/meta/0054_snapshot.json b/packages/db/drizzle/meta/0054_snapshot.jsonnew file mode 100644index 000000000..6665f5d54--- /dev/null+++ b/packages/db/drizzle/meta/0054_snapshot.json@@ -0,0 +1,3459 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "fa90adb7-69d9-419c-baf9-3a73922e9e43",+ "prevId": "cd3deb34-e4c8-4ae2-aa4e-bc0f7d9517f5",+ "tables": {+ "workspace": {+ "name": "workspace",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "stripe_id": {+ "name": "stripe_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "subscription_id": {+ "name": "subscription_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "plan": {+ "name": "plan",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "ends_at": {+ "name": "ends_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "paid_until": {+ "name": "paid_until",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "limits": {+ "name": "limits",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{}'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "dsn": {+ "name": "dsn",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "workspace_slug_unique": {+ "name": "workspace_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "workspace_stripe_id_unique": {+ "name": "workspace_stripe_id_unique",+ "columns": [+ "stripe_id"+ ],+ "isUnique": true+ },+ "workspace_id_dsn_unique": {+ "name": "workspace_id_dsn_unique",+ "columns": [+ "id",+ "dsn"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "account": {+ "name": "account",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider_account_id": {+ "name": "provider_account_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "account_user_id_user_id_fk": {+ "name": "account_user_id_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "account_provider_provider_account_id_pk": {+ "columns": [+ "provider",+ "provider_account_id"+ ],+ "name": "account_provider_provider_account_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "session": {+ "name": "session",+ "columns": {+ "session_token": {+ "name": "session_token",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_user_id_user_id_fk": {+ "name": "session_user_id_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "tenant_id": {+ "name": "tenant_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "first_name": {+ "name": "first_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "last_name": {+ "name": "last_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "photo_url": {+ "name": "photo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "user_tenant_id_unique": {+ "name": "user_tenant_id_unique",+ "columns": [+ "tenant_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "users_to_workspaces": {+ "name": "users_to_workspaces",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "users_to_workspaces_user_id_user_id_fk": {+ "name": "users_to_workspaces_user_id_user_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "users_to_workspaces_workspace_id_workspace_id_fk": {+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "users_to_workspaces_user_id_workspace_id_pk": {+ "columns": [+ "user_id",+ "workspace_id"+ ],+ "name": "users_to_workspaces_user_id_workspace_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "verification_token": {+ "name": "verification_token",+ "columns": {+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "verification_token_identifier_token_pk": {+ "columns": [+ "identifier",+ "token"+ ],+ "name": "verification_token_identifier_token_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report_to_monitors": {+ "name": "status_report_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_to_monitors_monitor_id_monitor_id_fk": {+ "name": "status_report_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_to_monitors_status_report_id_status_report_id_fk": {+ "name": "status_report_to_monitors_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_to_monitors_monitor_id_status_report_id_pk": {+ "columns": [+ "monitor_id",+ "status_report_id"+ ],+ "name": "status_report_to_monitors_monitor_id_status_report_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report": {+ "name": "status_report",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_workspace_id_workspace_id_fk": {+ "name": "status_report_workspace_id_workspace_id_fk",+ "tableFrom": "status_report",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "status_report_page_id_page_id_fk": {+ "name": "status_report_page_id_page_id_fk",+ "tableFrom": "status_report",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report_update": {+ "name": "status_report_update",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_update_status_report_id_status_report_id_fk": {+ "name": "status_report_update_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_update",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "integration": {+ "name": "integration",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "credential": {+ "name": "credential",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "integration_workspace_id_workspace_id_fk": {+ "name": "integration_workspace_id_workspace_id_fk",+ "tableFrom": "integration",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page": {+ "name": "page",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "slug": {+ "name": "slug",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "custom_domain": {+ "name": "custom_domain",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "published": {+ "name": "published",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "force_theme": {+ "name": "force_theme",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'system'"+ },+ "password": {+ "name": "password",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "password_protected": {+ "name": "password_protected",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "access_type": {+ "name": "access_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'public'"+ },+ "auth_email_domains": {+ "name": "auth_email_domains",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "homepage_url": {+ "name": "homepage_url",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "contact_url": {+ "name": "contact_url",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "legacy_page": {+ "name": "legacy_page",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "configuration": {+ "name": "configuration",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "show_monitor_values": {+ "name": "show_monitor_values",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_slug_unique": {+ "name": "page_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "page_workspace_id_workspace_id_fk": {+ "name": "page_workspace_id_workspace_id_fk",+ "tableFrom": "page",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor": {+ "name": "monitor",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "job_type": {+ "name": "job_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'http'"+ },+ "periodicity": {+ "name": "periodicity",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "active": {+ "name": "active",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "regions": {+ "name": "regions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "url": {+ "name": "url",+ "type": "text(2048)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "external_name": {+ "name": "external_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "headers": {+ "name": "headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'GET'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "timeout": {+ "name": "timeout",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 45000+ },+ "degraded_after": {+ "name": "degraded_after",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "assertions": {+ "name": "assertions",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "otel_endpoint": {+ "name": "otel_endpoint",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "otel_headers": {+ "name": "otel_headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "public": {+ "name": "public",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "retry": {+ "name": "retry",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 3+ },+ "follow_redirects": {+ "name": "follow_redirects",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_workspace_id_workspace_id_fk": {+ "name": "monitor_workspace_id_workspace_id_fk",+ "tableFrom": "monitor",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitors_to_pages": {+ "name": "monitors_to_pages",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "order": {+ "name": "order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ },+ "monitor_group_id": {+ "name": "monitor_group_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "group_order": {+ "name": "group_order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitors_to_pages_monitor_id_monitor_id_fk": {+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitors_to_pages_page_id_page_id_fk": {+ "name": "monitors_to_pages_page_id_page_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitors_to_pages_monitor_group_id_monitor_group_id_fk": {+ "name": "monitors_to_pages_monitor_group_id_monitor_group_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "monitor_group",+ "columnsFrom": [+ "monitor_group_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitors_to_pages_monitor_id_page_id_pk": {+ "columns": [+ "monitor_id",+ "page_id"+ ],+ "name": "monitors_to_pages_monitor_id_page_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_subscriber": {+ "name": "page_subscriber",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "accepted_at": {+ "name": "accepted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "unsubscribed_at": {+ "name": "unsubscribed_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "page_subscriber_page_id_page_id_fk": {+ "name": "page_subscriber_page_id_page_id_fk",+ "tableFrom": "page_subscriber",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notification": {+ "name": "notification",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'{}'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "notification_workspace_id_workspace_id_fk": {+ "name": "notification_workspace_id_workspace_id_fk",+ "tableFrom": "notification",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notification_trigger": {+ "name": "notification_trigger",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "notification_id": {+ "name": "notification_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cron_timestamp": {+ "name": "cron_timestamp",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "notification_id_monitor_id_crontimestampe": {+ "name": "notification_id_monitor_id_crontimestampe",+ "columns": [+ "notification_id",+ "monitor_id",+ "cron_timestamp"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "notification_trigger_monitor_id_monitor_id_fk": {+ "name": "notification_trigger_monitor_id_monitor_id_fk",+ "tableFrom": "notification_trigger",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notification_trigger_notification_id_notification_id_fk": {+ "name": "notification_trigger_notification_id_notification_id_fk",+ "tableFrom": "notification_trigger",+ "tableTo": "notification",+ "columnsFrom": [+ "notification_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notifications_to_monitors": {+ "name": "notifications_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "notification_id": {+ "name": "notification_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "notifications_to_monitors_monitor_id_monitor_id_fk": {+ "name": "notifications_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notifications_to_monitors_notification_id_notification_id_fk": {+ "name": "notifications_to_monitors_notification_id_notification_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "notification",+ "columnsFrom": [+ "notification_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "notifications_to_monitors_monitor_id_notification_id_pk": {+ "columns": [+ "monitor_id",+ "notification_id"+ ],+ "name": "notifications_to_monitors_monitor_id_notification_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_status": {+ "name": "monitor_status",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "region": {+ "name": "region",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_status_idx": {+ "name": "monitor_status_idx",+ "columns": [+ "monitor_id",+ "region"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_status_monitor_id_monitor_id_fk": {+ "name": "monitor_status_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_status",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitor_status_monitor_id_region_pk": {+ "columns": [+ "monitor_id",+ "region"+ ],+ "name": "monitor_status_monitor_id_region_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "invitation": {+ "name": "invitation",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "accepted_at": {+ "name": "accepted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "incident": {+ "name": "incident",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'triage'"+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "started_at": {+ "name": "started_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "acknowledged_at": {+ "name": "acknowledged_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "acknowledged_by": {+ "name": "acknowledged_by",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resolved_at": {+ "name": "resolved_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resolved_by": {+ "name": "resolved_by",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "incident_screenshot_url": {+ "name": "incident_screenshot_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "recovery_screenshot_url": {+ "name": "recovery_screenshot_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "auto_resolved": {+ "name": "auto_resolved",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "incident_monitor_id_started_at_unique": {+ "name": "incident_monitor_id_started_at_unique",+ "columns": [+ "monitor_id",+ "started_at"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "incident_monitor_id_monitor_id_fk": {+ "name": "incident_monitor_id_monitor_id_fk",+ "tableFrom": "incident",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set default",+ "onUpdate": "no action"+ },+ "incident_workspace_id_workspace_id_fk": {+ "name": "incident_workspace_id_workspace_id_fk",+ "tableFrom": "incident",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "incident_acknowledged_by_user_id_fk": {+ "name": "incident_acknowledged_by_user_id_fk",+ "tableFrom": "incident",+ "tableTo": "user",+ "columnsFrom": [+ "acknowledged_by"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "incident_resolved_by_user_id_fk": {+ "name": "incident_resolved_by_user_id_fk",+ "tableFrom": "incident",+ "tableTo": "user",+ "columnsFrom": [+ "resolved_by"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_tag": {+ "name": "monitor_tag",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_tag_workspace_id_workspace_id_fk": {+ "name": "monitor_tag_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_tag",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_tag_to_monitor": {+ "name": "monitor_tag_to_monitor",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_tag_id": {+ "name": "monitor_tag_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_tag_to_monitor_monitor_id_monitor_id_fk": {+ "name": "monitor_tag_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_tag_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk": {+ "name": "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk",+ "tableFrom": "monitor_tag_to_monitor",+ "tableTo": "monitor_tag",+ "columnsFrom": [+ "monitor_tag_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk": {+ "columns": [+ "monitor_id",+ "monitor_tag_id"+ ],+ "name": "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "application": {+ "name": "application",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "dsn": {+ "name": "dsn",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "application_dsn_unique": {+ "name": "application_dsn_unique",+ "columns": [+ "dsn"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "application_workspace_id_workspace_id_fk": {+ "name": "application_workspace_id_workspace_id_fk",+ "tableFrom": "application",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "maintenance": {+ "name": "maintenance",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "from": {+ "name": "from",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "to": {+ "name": "to",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "maintenance_workspace_id_workspace_id_fk": {+ "name": "maintenance_workspace_id_workspace_id_fk",+ "tableFrom": "maintenance",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "maintenance_page_id_page_id_fk": {+ "name": "maintenance_page_id_page_id_fk",+ "tableFrom": "maintenance",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "maintenance_to_monitor": {+ "name": "maintenance_to_monitor",+ "columns": {+ "maintenance_id": {+ "name": "maintenance_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "maintenance_to_monitor_maintenance_id_maintenance_id_fk": {+ "name": "maintenance_to_monitor_maintenance_id_maintenance_id_fk",+ "tableFrom": "maintenance_to_monitor",+ "tableTo": "maintenance",+ "columnsFrom": [+ "maintenance_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "maintenance_to_monitor_monitor_id_monitor_id_fk": {+ "name": "maintenance_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "maintenance_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "maintenance_to_monitor_maintenance_id_monitor_id_pk": {+ "columns": [+ "maintenance_id",+ "monitor_id"+ ],+ "name": "maintenance_to_monitor_maintenance_id_monitor_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "check": {+ "name": "check",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "regions": {+ "name": "regions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "url": {+ "name": "url",+ "type": "text(4096)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "headers": {+ "name": "headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'GET'"+ },+ "count_requests": {+ "name": "count_requests",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 1+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "check_workspace_id_workspace_id_fk": {+ "name": "check_workspace_id_workspace_id_fk",+ "tableFrom": "check",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_run": {+ "name": "monitor_run",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "runned_at": {+ "name": "runned_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_run_workspace_id_workspace_id_fk": {+ "name": "monitor_run_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_run",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "monitor_run_monitor_id_monitor_id_fk": {+ "name": "monitor_run_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_run",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "private_location": {+ "name": "private_location",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "last_seen_at": {+ "name": "last_seen_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "private_location_workspace_id_workspace_id_fk": {+ "name": "private_location_workspace_id_workspace_id_fk",+ "tableFrom": "private_location",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "private_location_to_monitor": {+ "name": "private_location_to_monitor",+ "columns": {+ "private_location_id": {+ "name": "private_location_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "private_location_to_monitor_private_location_id_private_location_id_fk": {+ "name": "private_location_to_monitor_private_location_id_private_location_id_fk",+ "tableFrom": "private_location_to_monitor",+ "tableTo": "private_location",+ "columnsFrom": [+ "private_location_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "private_location_to_monitor_monitor_id_monitor_id_fk": {+ "name": "private_location_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "private_location_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_group": {+ "name": "monitor_group",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_group_workspace_id_workspace_id_fk": {+ "name": "monitor_group_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_group",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitor_group_page_id_page_id_fk": {+ "name": "monitor_group_page_id_page_id_fk",+ "tableFrom": "monitor_group",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer": {+ "name": "viewer",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "viewer_email_unique": {+ "name": "viewer_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer_accounts": {+ "name": "viewer_accounts",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "providerAccountId": {+ "name": "providerAccountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "viewer_accounts_user_id_viewer_id_fk": {+ "name": "viewer_accounts_user_id_viewer_id_fk",+ "tableFrom": "viewer_accounts",+ "tableTo": "viewer",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "viewer_accounts_provider_providerAccountId_pk": {+ "columns": [+ "provider",+ "providerAccountId"+ ],+ "name": "viewer_accounts_provider_providerAccountId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer_session": {+ "name": "viewer_session",+ "columns": {+ "session_token": {+ "name": "session_token",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "viewer_session_user_id_viewer_id_fk": {+ "name": "viewer_session_user_id_viewer_id_fk",+ "tableFrom": "viewer_session",+ "tableTo": "viewer",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "api_key": {+ "name": "api_key",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "prefix": {+ "name": "prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "hashed_token": {+ "name": "hashed_token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_by_id": {+ "name": "created_by_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "api_key_prefix_unique": {+ "name": "api_key_prefix_unique",+ "columns": [+ "prefix"+ ],+ "isUnique": true+ },+ "api_key_hashed_token_unique": {+ "name": "api_key_hashed_token_unique",+ "columns": [+ "hashed_token"+ ],+ "isUnique": true+ },+ "api_key_prefix_idx": {+ "name": "api_key_prefix_idx",+ "columns": [+ "prefix"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "api_key_workspace_id_workspace_id_fk": {+ "name": "api_key_workspace_id_workspace_id_fk",+ "tableFrom": "api_key",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "api_key_created_by_id_user_id_fk": {+ "name": "api_key_created_by_id_user_id_fk",+ "tableFrom": "api_key",+ "tableTo": "user",+ "columnsFrom": [+ "created_by_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "maintenance_to_page_component": {+ "name": "maintenance_to_page_component",+ "columns": {+ "maintenance_id": {+ "name": "maintenance_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "maintenance_to_page_component_maintenance_id_maintenance_id_fk": {+ "name": "maintenance_to_page_component_maintenance_id_maintenance_id_fk",+ "tableFrom": "maintenance_to_page_component",+ "tableTo": "maintenance",+ "columnsFrom": [+ "maintenance_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "maintenance_to_page_component_page_component_id_page_component_id_fk": {+ "name": "maintenance_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "maintenance_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "maintenance_to_page_component_maintenance_id_page_component_id_pk": {+ "columns": [+ "maintenance_id",+ "page_component_id"+ ],+ "name": "maintenance_to_page_component_maintenance_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_component": {+ "name": "page_component",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'monitor'"+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "order": {+ "name": "order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ },+ "group_id": {+ "name": "group_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "group_order": {+ "name": "group_order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ },+ "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_component_page_id_monitor_id_unique": {+ "name": "page_component_page_id_monitor_id_unique",+ "columns": [+ "page_id",+ "monitor_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "page_component_workspace_id_workspace_id_fk": {+ "name": "page_component_workspace_id_workspace_id_fk",+ "tableFrom": "page_component",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_page_id_page_id_fk": {+ "name": "page_component_page_id_page_id_fk",+ "tableFrom": "page_component",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_monitor_id_monitor_id_fk": {+ "name": "page_component_monitor_id_monitor_id_fk",+ "tableFrom": "page_component",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_group_id_page_component_groups_id_fk": {+ "name": "page_component_group_id_page_component_groups_id_fk",+ "tableFrom": "page_component",+ "tableTo": "page_component_groups",+ "columnsFrom": [+ "group_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {+ "page_component_type_check": {+ "name": "page_component_type_check",+ "value": "\"page_component\".\"type\" = 'monitor' AND \"page_component\".\"monitor_id\" IS NOT NULL OR \"page_component\".\"type\" = 'external' AND \"page_component\".\"monitor_id\" IS NULL"+ }+ }+ },+ "status_report_to_page_component": {+ "name": "status_report_to_page_component",+ "columns": {+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_to_page_component_status_report_id_status_report_id_fk": {+ "name": "status_report_to_page_component_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_to_page_component",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_to_page_component_page_component_id_page_component_id_fk": {+ "name": "status_report_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "status_report_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_to_page_component_status_report_id_page_component_id_pk": {+ "columns": [+ "status_report_id",+ "page_component_id"+ ],+ "name": "status_report_to_page_component_status_report_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_component_groups": {+ "name": "page_component_groups",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "page_component_groups_workspace_id_workspace_id_fk": {+ "name": "page_component_groups_workspace_id_workspace_id_fk",+ "tableFrom": "page_component_groups",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_groups_page_id_page_id_fk": {+ "name": "page_component_groups_page_id_page_id_fk",+ "tableFrom": "page_component_groups",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 00ea224ec..f19843fd0 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -379,6 +379,13 @@"when": 1768490525276,"tag": "0053_dark_orphan","breakpoints": true+ },+ {+ "idx": 54,+ "version": "6",+ "when": 1768564852930,+ "tag": "0054_bitter_lilandra",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/index.ts b/packages/db/src/index.tsindex 2e05a8b86..846029ee4 100644--- a/packages/db/src/index.ts+++ b/packages/db/src/index.ts@@ -1,5 +1,6 @@export * as schema from "./schema";export * from "drizzle-orm";export * from "./db";+export * from "./sync";// doing this because the external module not working see : https://github.com/vercel/next.js/issues/43433// export * from "./sync-db";diff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.tsindex ad14091c4..edff78a84 100644--- a/packages/db/src/schema/index.ts+++ b/packages/db/src/schema/index.ts@@ -19,3 +19,5 @@ export * from "./private_locations";export * from "./monitor_groups";export * from "./viewers";export * from "./api-keys";+export * from "./page_components";+export * from "./page_component_groups";diff --git a/packages/db/src/schema/page_component_groups/index.ts b/packages/db/src/schema/page_component_groups/index.tsnew file mode 100644index 000000000..b3ea1ca37--- /dev/null+++ b/packages/db/src/schema/page_component_groups/index.ts@@ -0,0 +1,2 @@+export * from "./page_component_groups";+export * from "./validation";diff --git a/packages/db/src/schema/page_component_groups/page_component_groups.ts b/packages/db/src/schema/page_component_groups/page_component_groups.tsnew file mode 100644index 000000000..a7445797b--- /dev/null+++ b/packages/db/src/schema/page_component_groups/page_component_groups.ts@@ -0,0 +1,39 @@+import { relations, sql } from "drizzle-orm";+import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";++import { pageComponent } from "../page_components";+import { page } from "../pages";+import { workspace } from "../workspaces";++export const pageComponentGroup = sqliteTable("page_component_groups", {+ id: integer("id").primaryKey(),+ workspaceId: integer("workspace_id")+ .references(() => workspace.id, { onDelete: "cascade" })+ .notNull(),+ pageId: integer("page_id")+ .references(() => page.id, { onDelete: "cascade" })+ .notNull(),+ name: text("name").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 pageComponentGroupRelations = relations(+ pageComponentGroup,+ ({ one, many }) => ({+ workspace: one(workspace, {+ fields: [pageComponentGroup.workspaceId],+ references: [workspace.id],+ }),+ page: one(page, {+ fields: [pageComponentGroup.pageId],+ references: [page.id],+ }),+ pageComponents: many(pageComponent),+ }),+);diff --git a/packages/db/src/schema/page_component_groups/validation.ts b/packages/db/src/schema/page_component_groups/validation.tsnew file mode 100644index 000000000..afedc89ab--- /dev/null+++ b/packages/db/src/schema/page_component_groups/validation.ts@@ -0,0 +1,15 @@+import { createInsertSchema, createSelectSchema } from "drizzle-zod";+import type { z } from "zod";++import { pageComponentGroup } from "./page_component_groups";++export const selectPageComponentGroupSchema =+ createSelectSchema(pageComponentGroup);++export const insertPageComponentGroupSchema =+ createInsertSchema(pageComponentGroup);++export type InsertPageComponentGroup = z.infer<+ typeof insertPageComponentGroupSchema+>;+export type PageComponentGroup = z.infer<typeof selectPageComponentGroupSchema>;diff --git a/packages/db/src/schema/page_components/index.ts b/packages/db/src/schema/page_components/index.tsnew file mode 100644index 000000000..b23cc46fc--- /dev/null+++ b/packages/db/src/schema/page_components/index.ts@@ -0,0 +1,2 @@+export * from "./page_components";+export * from "./validation";diff --git a/packages/db/src/schema/page_components/page_components.ts b/packages/db/src/schema/page_components/page_components.tsnew file mode 100644index 000000000..c79422895--- /dev/null+++ b/packages/db/src/schema/page_components/page_components.ts@@ -0,0 +1,150 @@+import { relations, sql } from "drizzle-orm";+import {+ check,+ integer,+ primaryKey,+ sqliteTable,+ text,+ unique,+} from "drizzle-orm/sqlite-core";++import { maintenance } from "../maintenances";+import { monitor } from "../monitors";+import { pageComponentGroup } from "../page_component_groups";+import { page } from "../pages";+import { statusReport } from "../status_reports";+import { workspace } from "../workspaces";++export const pageComponentTypes = ["external", "monitor"] as const;++export const pageComponent = sqliteTable(+ "page_component",+ {+ id: integer("id").primaryKey(),+ workspaceId: integer("workspace_id")+ .notNull()+ .references(() => workspace.id, { onDelete: "cascade" }),+ pageId: integer("page_id")+ .notNull()+ .references(() => page.id, { onDelete: "cascade" }),+ type: text("type", { enum: pageComponentTypes })+ .notNull()+ .default("monitor"),+ monitorId: integer("monitor_id").references(() => monitor.id, {+ onDelete: "cascade",+ }),+ name: text("name").notNull(),+ description: text("description"),+ order: integer("order").default(0),+ groupId: integer("group_id").references(() => pageComponentGroup.id, {+ onDelete: "set null",+ }),+ groupOrder: integer("group_order").default(0),++ createdAt: integer("created_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+ updatedAt: integer("updated_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+ },+ (t) => [+ unique("page_component_page_id_monitor_id_unique").on(+ t.pageId,+ t.monitorId,+ ),+ check(+ "page_component_type_check",+ // NOTE: This check ensures that either the component is a monitor or an external component, but not both.+ sql`${t.type} = 'monitor' AND ${t.monitorId} IS NOT NULL OR ${t.type} = 'external' AND ${t.monitorId} IS NULL`,+ ),+ ],+);++export const pageComponentRelations = relations(+ pageComponent,+ ({ one, many }) => ({+ workspace: one(workspace, {+ fields: [pageComponent.workspaceId],+ references: [workspace.id],+ }),+ page: one(page, {+ fields: [pageComponent.pageId],+ references: [page.id],+ }),+ monitor: one(monitor, {+ fields: [pageComponent.monitorId],+ references: [monitor.id],+ }),+ group: one(pageComponentGroup, {+ fields: [pageComponent.groupId],+ references: [pageComponentGroup.id],+ }),+ statusReportsToPageComponents: many(statusReportsToPageComponents),+ maintenancesToPageComponents: many(maintenancesToPageComponents),+ }),+);++export const maintenancesToPageComponents = sqliteTable(+ "maintenance_to_page_component",+ {+ maintenanceId: integer("maintenance_id")+ .notNull()+ .references(() => maintenance.id, { onDelete: "cascade" }),+ pageComponentId: integer("page_component_id")+ .notNull()+ .references(() => pageComponent.id, { onDelete: "cascade" }),+ createdAt: integer("created_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+ },+ (t) => ({+ pk: primaryKey({ columns: [t.maintenanceId, t.pageComponentId] }),+ }),+);++export const maintenancesToPageComponentsRelations = relations(+ maintenancesToPageComponents,+ ({ one }) => ({+ maintenance: one(maintenance, {+ fields: [maintenancesToPageComponents.maintenanceId],+ references: [maintenance.id],+ }),+ pageComponent: one(pageComponent, {+ fields: [maintenancesToPageComponents.pageComponentId],+ references: [pageComponent.id],+ }),+ }),+);++export const statusReportsToPageComponents = sqliteTable(+ "status_report_to_page_component",+ {+ statusReportId: integer("status_report_id")+ .notNull()+ .references(() => statusReport.id, { onDelete: "cascade" }),+ pageComponentId: integer("page_component_id")+ .notNull()+ .references(() => pageComponent.id, { onDelete: "cascade" }),+ createdAt: integer("created_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+ },+ (t) => ({+ pk: primaryKey({ columns: [t.statusReportId, t.pageComponentId] }),+ }),+);++export const statusReportsToPageComponentsRelations = relations(+ statusReportsToPageComponents,+ ({ one }) => ({+ statusReport: one(statusReport, {+ fields: [statusReportsToPageComponents.statusReportId],+ references: [statusReport.id],+ }),+ pageComponent: one(pageComponent, {+ fields: [statusReportsToPageComponents.pageComponentId],+ references: [pageComponent.id],+ }),+ }),+);diff --git a/packages/db/src/schema/page_components/validation.ts b/packages/db/src/schema/page_components/validation.tsnew file mode 100644index 000000000..a7f2e6dbe--- /dev/null+++ b/packages/db/src/schema/page_components/validation.ts@@ -0,0 +1,29 @@+import { createInsertSchema, createSelectSchema } from "drizzle-zod";+import type { z } from "zod";++import { pageComponent } from "./page_components";++export const selectPageComponentSchema = createSelectSchema(pageComponent);++export const insertPageComponentSchema = createInsertSchema(pageComponent, {+ name: (schema) => schema.min(1),+}).refine(+ (data) => {+ // monitorId must be set when type='monitor'+ if (data.type === "monitor" && !data.monitorId) {+ return false;+ }+ // monitorId must be null when type='external'+ if (data.type === "external" && data.monitorId) {+ return false;+ }+ return true;+ },+ {+ message:+ "monitorId must be set when type is 'monitor' and must be null when type is 'external'",+ },+);++export type InsertPageComponent = z.infer<typeof insertPageComponentSchema>;+export type PageComponent = z.infer<typeof selectPageComponentSchema>;diff --git a/packages/db/src/sync.ts b/packages/db/src/sync.tsnew file mode 100644index 000000000..d092dd9f0--- /dev/null+++ b/packages/db/src/sync.ts@@ -0,0 +1,515 @@+import { and, eq, inArray } from "drizzle-orm";++import type { db } from "./db";+import {+ maintenance,+ maintenancesToPageComponents,+ monitor,+ pageComponent,+ pageComponentGroup,+ statusReport,+ statusReportsToPageComponents,+} from "./schema";++// Type that works with both LibSQLDatabase and SQLiteTransaction+// Using any to allow both db instance and transaction to be passed+// biome-ignore lint/suspicious/noExplicitAny: Compatible with both db and transaction+type DB = typeof db;+// Extract transaction type from the callback parameter of db.transaction()+type Transaction = Parameters<Parameters<DB["transaction"]>[0]>[0];++// ============================================================================+// Monitor Group <-> Page Component Group Sync+// ============================================================================++/**+ * Syncs a monitor group insert to page_component_groups+ */+export async function syncMonitorGroupInsert(+ db: DB | Transaction,+ data: {+ id: number;+ workspaceId: number;+ pageId: number;+ name: string;+ },+) {+ await db+ .insert(pageComponentGroup)+ .values({+ id: data.id,+ workspaceId: data.workspaceId,+ pageId: data.pageId,+ name: data.name,+ })+ .onConflictDoNothing();+}++/**+ * Syncs a monitor group delete to page_component_groups+ */+export async function syncMonitorGroupDelete(+ db: DB | Transaction,+ monitorGroupId: number,+) {+ await db+ .delete(pageComponentGroup)+ .where(eq(pageComponentGroup.id, monitorGroupId));+}++/**+ * Syncs multiple monitor group deletes to page_component_groups+ */+export async function syncMonitorGroupDeleteMany(+ db: DB | Transaction,+ monitorGroupIds: number[],+) {+ if (monitorGroupIds.length === 0) return;+ await db+ .delete(pageComponentGroup)+ .where(inArray(pageComponentGroup.id, monitorGroupIds));+}++// ============================================================================+// Monitors to Pages <-> Page Component Sync+// ============================================================================++/**+ * Syncs a monitors_to_pages insert to page_component+ * Requires monitor data to get name and workspace_id+ */+export async function syncMonitorsToPageInsert(+ db: DB | Transaction,+ data: {+ monitorId: number;+ pageId: number;+ order?: number;+ monitorGroupId?: number | null;+ groupOrder?: number;+ },+) {+ // Get monitor data for name and workspace_id+ const monitorData = await db+ .select({+ id: monitor.id,+ name: monitor.name,+ externalName: monitor.externalName,+ workspaceId: monitor.workspaceId,+ })+ .from(monitor)+ .where(eq(monitor.id, data.monitorId))+ .get();++ if (!monitorData || !monitorData.workspaceId) return;++ await db+ .insert(pageComponent)+ .values({+ workspaceId: monitorData.workspaceId,+ pageId: data.pageId,+ type: "monitor",+ monitorId: data.monitorId,+ name: monitorData.externalName || monitorData.name,+ order: data.order ?? 0,+ groupId: data.monitorGroupId ?? null,+ groupOrder: data.groupOrder ?? 0,+ })+ .onConflictDoNothing();+}++/**+ * Syncs multiple monitors_to_pages inserts to page_component+ */+export async function syncMonitorsToPageInsertMany(+ db: DB | Transaction,+ items: Array<{+ monitorId: number;+ pageId: number;+ order?: number;+ monitorGroupId?: number | null;+ groupOrder?: number;+ }>,+) {+ if (items.length === 0) return;++ // Get all monitor data in one query+ const monitorIds = [...new Set(items.map((item) => item.monitorId))];+ const monitors = await db+ .select({+ id: monitor.id,+ name: monitor.name,+ externalName: monitor.externalName,+ workspaceId: monitor.workspaceId,+ })+ .from(monitor)+ .where(inArray(monitor.id, monitorIds));++ const monitorMap = new Map(monitors.map((m) => [m.id, m]));++ const values = items+ .map((item) => {+ const m = monitorMap.get(item.monitorId);+ if (!m || !m.workspaceId) return null;+ return {+ workspaceId: m.workspaceId,+ pageId: item.pageId,+ type: "monitor" as const,+ monitorId: item.monitorId,+ name: m.externalName || m.name,+ order: item.order ?? 0,+ groupId: item.monitorGroupId ?? null,+ groupOrder: item.groupOrder ?? 0,+ };+ })+ .filter((v): v is NonNullable<typeof v> => v !== null);++ if (values.length === 0) return;++ await db.insert(pageComponent).values(values).onConflictDoNothing();+}++/**+ * Syncs a monitors_to_pages delete to page_component+ */+export async function syncMonitorsToPageDelete(+ db: DB | Transaction,+ data: { monitorId: number; pageId: number },+) {+ await db+ .delete(pageComponent)+ .where(+ and(+ eq(pageComponent.monitorId, data.monitorId),+ eq(pageComponent.pageId, data.pageId),+ ),+ );+}++/**+ * Syncs monitors_to_pages deletes for a specific page to page_component+ */+export async function syncMonitorsToPageDeleteByPage(+ db: DB | Transaction,+ pageId: number,+) {+ await db+ .delete(pageComponent)+ .where(+ and(eq(pageComponent.pageId, pageId), eq(pageComponent.type, "monitor")),+ );+}++/**+ * Syncs monitors_to_pages deletes for specific monitors to page_component+ */+export async function syncMonitorsToPageDeleteByMonitors(+ db: DB | Transaction,+ monitorIds: number[],+) {+ if (monitorIds.length === 0) return;+ await db+ .delete(pageComponent)+ .where(inArray(pageComponent.monitorId, monitorIds));+}++// ============================================================================+// Status Report to Monitors <-> Status Report to Page Components Sync+// ============================================================================++/**+ * Syncs a status_report_to_monitors insert to status_report_to_page_component+ */+export async function syncStatusReportToMonitorInsert(+ db: DB | Transaction,+ data: { statusReportId: number; monitorId: number },+) {+ // Get the status report's page_id+ const report = await db+ .select({ pageId: statusReport.pageId })+ .from(statusReport)+ .where(eq(statusReport.id, data.statusReportId))+ .get();++ // Find matching page_components+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(+ and(+ eq(pageComponent.monitorId, data.monitorId),+ report?.pageId+ ? eq(pageComponent.pageId, report.pageId)+ : // If no page_id on status report, match all page_components with this monitor+ eq(pageComponent.monitorId, data.monitorId),+ ),+ );++ if (components.length === 0) return;++ await db+ .insert(statusReportsToPageComponents)+ .values(+ components.map((c) => ({+ statusReportId: data.statusReportId,+ pageComponentId: c.id,+ })),+ )+ .onConflictDoNothing();+}++/**+ * Syncs multiple status_report_to_monitors inserts to status_report_to_page_component+ */+export async function syncStatusReportToMonitorInsertMany(+ db: DB | Transaction,+ statusReportId: number,+ monitorIds: number[],+) {+ if (monitorIds.length === 0) return;++ // Get the status report's page_id+ const report = await db+ .select({ pageId: statusReport.pageId })+ .from(statusReport)+ .where(eq(statusReport.id, statusReportId))+ .get();++ // Find matching page_components for all monitors+ const components = await db+ .select({ id: pageComponent.id, monitorId: pageComponent.monitorId })+ .from(pageComponent)+ .where(+ and(+ inArray(pageComponent.monitorId, monitorIds),+ report?.pageId+ ? eq(pageComponent.pageId, report.pageId)+ : // If no page_id, we need to be careful - get components that match the monitor+ inArray(pageComponent.monitorId, monitorIds),+ ),+ );++ if (components.length === 0) return;++ await db+ .insert(statusReportsToPageComponents)+ .values(+ components.map((c) => ({+ statusReportId,+ pageComponentId: c.id,+ })),+ )+ .onConflictDoNothing();+}++/**+ * Syncs a status_report_to_monitors delete to status_report_to_page_component+ */+export async function syncStatusReportToMonitorDelete(+ db: DB | Transaction,+ data: { statusReportId: number; monitorId: number },+) {+ // Find page_components with this monitor+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.monitorId, data.monitorId));++ if (components.length === 0) return;++ await db.delete(statusReportsToPageComponents).where(+ and(+ eq(statusReportsToPageComponents.statusReportId, data.statusReportId),+ inArray(+ statusReportsToPageComponents.pageComponentId,+ components.map((c) => c.id),+ ),+ ),+ );+}++/**+ * Syncs status_report_to_monitors deletes for a specific status report+ */+export async function syncStatusReportToMonitorDeleteByStatusReport(+ db: DB | Transaction,+ statusReportId: number,+) {+ await db+ .delete(statusReportsToPageComponents)+ .where(eq(statusReportsToPageComponents.statusReportId, statusReportId));+}++/**+ * Syncs status_report_to_monitors deletes for specific monitors+ */+export async function syncStatusReportToMonitorDeleteByMonitors(+ db: DB | Transaction,+ monitorIds: number[],+) {+ if (monitorIds.length === 0) return;++ // Find page_components with these monitors+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(inArray(pageComponent.monitorId, monitorIds));++ if (components.length === 0) return;++ await db.delete(statusReportsToPageComponents).where(+ inArray(+ statusReportsToPageComponents.pageComponentId,+ components.map((c) => c.id),+ ),+ );+}++// ============================================================================+// Maintenance to Monitor <-> Maintenance to Page Component Sync+// ============================================================================++/**+ * Syncs a maintenance_to_monitor insert to maintenance_to_page_component+ */+export async function syncMaintenanceToMonitorInsert(+ db: DB | Transaction,+ data: { maintenanceId: number; monitorId: number },+) {+ // Get the maintenance's page_id+ const maint = await db+ .select({ pageId: maintenance.pageId })+ .from(maintenance)+ .where(eq(maintenance.id, data.maintenanceId))+ .get();++ // Find matching page_components+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(+ and(+ eq(pageComponent.monitorId, data.monitorId),+ maint?.pageId+ ? eq(pageComponent.pageId, maint.pageId)+ : eq(pageComponent.monitorId, data.monitorId),+ ),+ );++ if (components.length === 0) return;++ await db+ .insert(maintenancesToPageComponents)+ .values(+ components.map((c) => ({+ maintenanceId: data.maintenanceId,+ pageComponentId: c.id,+ })),+ )+ .onConflictDoNothing();+}++/**+ * Syncs multiple maintenance_to_monitor inserts to maintenance_to_page_component+ */+export async function syncMaintenanceToMonitorInsertMany(+ db: DB | Transaction,+ maintenanceId: number,+ monitorIds: number[],+) {+ if (monitorIds.length === 0) return;++ // Get the maintenance's page_id+ const maint = await db+ .select({ pageId: maintenance.pageId })+ .from(maintenance)+ .where(eq(maintenance.id, maintenanceId))+ .get();++ // Find matching page_components for all monitors+ const components = await db+ .select({ id: pageComponent.id, monitorId: pageComponent.monitorId })+ .from(pageComponent)+ .where(+ and(+ inArray(pageComponent.monitorId, monitorIds),+ maint?.pageId+ ? eq(pageComponent.pageId, maint.pageId)+ : inArray(pageComponent.monitorId, monitorIds),+ ),+ );++ if (components.length === 0) return;++ await db+ .insert(maintenancesToPageComponents)+ .values(+ components.map((c) => ({+ maintenanceId,+ pageComponentId: c.id,+ })),+ )+ .onConflictDoNothing();+}++/**+ * Syncs a maintenance_to_monitor delete to maintenance_to_page_component+ */+export async function syncMaintenanceToMonitorDelete(+ db: DB | Transaction,+ data: { maintenanceId: number; monitorId: number },+) {+ // Find page_components with this monitor+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(eq(pageComponent.monitorId, data.monitorId));++ if (components.length === 0) return;++ await db.delete(maintenancesToPageComponents).where(+ and(+ eq(maintenancesToPageComponents.maintenanceId, data.maintenanceId),+ inArray(+ maintenancesToPageComponents.pageComponentId,+ components.map((c) => c.id),+ ),+ ),+ );+}++/**+ * Syncs maintenance_to_monitor deletes for a specific maintenance+ */+export async function syncMaintenanceToMonitorDeleteByMaintenance(+ db: DB | Transaction,+ maintenanceId: number,+) {+ await db+ .delete(maintenancesToPageComponents)+ .where(eq(maintenancesToPageComponents.maintenanceId, maintenanceId));+}++/**+ * Syncs maintenance_to_monitor deletes for specific monitors+ */+export async function syncMaintenanceToMonitorDeleteByMonitors(+ db: DB | Transaction,+ monitorIds: number[],+) {+ if (monitorIds.length === 0) return;++ // Find page_components with these monitors+ const components = await db+ .select({ id: pageComponent.id })+ .from(pageComponent)+ .where(inArray(pageComponent.monitorId, monitorIds));++ if (components.length === 0) return;++ await db.delete(maintenancesToPageComponents).where(+ inArray(+ maintenancesToPageComponents.pageComponentId,+ components.map((c) => c.id),+ ),+ );+}