Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🐛 add created at (#173)
Thibault Le Ouayfa7bb88c403d
diff --git a/packages/api/src/router/incident.ts b/packages/api/src/router/incident.tsindex 5eac805a9..c9cc90716 100644--- a/packages/api/src/router/incident.ts+++ b/packages/api/src/router/incident.ts@@ -7,7 +7,6 @@ import {insertIncidentSchema,insertIncidentSchemaWithMonitors,insertIncidentUpdateSchema,- monitor,monitorsToIncidents,selectIncidentSchema,selectIncidentUpdateSchema,diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.tsindex f54c19258..a5ebf866b 100644--- a/packages/api/src/router/monitor.ts+++ b/packages/api/src/router/monitor.ts@@ -191,16 +191,16 @@ export const monitorRouter = createTRPCRouter({const { regions, ...data } = opts.input;await opts.ctx.db.update(monitor)- .set({ ...data, regions: regions?.join(",") })+ .set({ ...data, regions: regions?.join(","), updatedAt: new Date() }).where(eq(monitor.id, opts.input.id)).returning().get();}),- updateMonitorStatus: protectedProcedure+ updateMonitorPeriodicity: protectedProcedure.input(z.object({id: z.number(),- status: insertMonitorSchema.pick({ periodicity: true }),+ data: insertMonitorSchema.pick({ periodicity: true }),}),).mutation(async (opts) => {@@ -227,7 +227,10 @@ export const monitorRouter = createTRPCRouter({await opts.ctx.db.update(monitor)- .set(opts.input.status)+ .set({+ periodicity: opts.input.data.periodicity,+ updatedAt: new Date(),+ }).where(eq(monitor.id, opts.input.id)).run();}),diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.tsindex bc96d44eb..2aa4f8719 100644--- a/packages/api/src/router/page.ts+++ b/packages/api/src/router/page.ts@@ -123,11 +123,38 @@ export const pageRouter = createTRPCRouter({updatePage: protectedProcedure.input(insertPageSchemaWithMonitors).mutation(async (opts) => {+ if (!opts.input.id) return;++ const currentUser = await opts.ctx.db+ .select()+ .from(user)+ .where(eq(user.tenantId, opts.ctx.auth.userId))+ .get();++ const result = await opts.ctx.db+ .select()+ .from(usersToWorkspaces)+ .where(eq(usersToWorkspaces.userId, currentUser.id))+ .all();+ const workspaceIds = result.map((workspace) => workspace.workspaceId);++ const pageToUpdate = await opts.ctx.db+ .select()+ .from(page)+ .where(+ and(+ eq(page.id, opts.input.id),+ inArray(page.workspaceId, workspaceIds),+ ),+ )+ .get();+ if (!pageToUpdate) return;+const { monitors, workspaceSlug, ...pageInput } = opts.input;if (!pageInput.id) return;const currentPage = await opts.ctx.db.update(page)- .set(pageInput)+ .set({ ...pageInput, updatedAt: new Date() }).where(eq(page.id, pageInput.id)).returning().get();diff --git a/packages/db/drizzle/0004_fixed_dakota_north.sql b/packages/db/drizzle/0004_fixed_dakota_north.sqlnew file mode 100644index 000000000..ebd5a91da--- /dev/null+++ b/packages/db/drizzle/0004_fixed_dakota_north.sql@@ -0,0 +1,11 @@+ALTER TABLE page RENAME COLUMN `updated_at` to `created_at` ;--> statement-breakpoint+ALTER TABLE page ADD `updated_at` integer;--> statement-breakpoint++ALTER TABLE monitor RENAME COLUMN `updated_at` to `created_at` ;--> statement-breakpoint+ALTER TABLE monitor ADD `updated_at` integer;--> statement-breakpoint++ALTER TABLE user RENAME COLUMN `updated_at` to `created_at` ;--> statement-breakpoint+ALTER TABLE user ADD `updated_at` integer;--> statement-breakpoint++ALTER TABLE workspace RENAME COLUMN `updated_at` to `created_at` ;--> statement-breakpoint+ALTER TABLE workspace ADD `updated_at` integer;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0004_snapshot.json b/packages/db/drizzle/meta/0004_snapshot.jsonnew file mode 100644index 000000000..1d13a5bfe--- /dev/null+++ b/packages/db/drizzle/meta/0004_snapshot.json@@ -0,0 +1,693 @@+{+ "version": "5",+ "dialect": "sqlite",+ "id": "c7088c9f-2521-43af-884e-b7b0b81b0cb9",+ "prevId": "f68fee05-786b-45d6-9e08-f793e7591577",+ "tables": {+ "incident": {+ "name": "incident",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text(4)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "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"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "incident_update": {+ "name": "incident_update",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text(4)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "incident_id": {+ "name": "incident_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "incident_update_incident_id_incident_id_fk": {+ "name": "incident_update_incident_id_incident_id_fk",+ "tableFrom": "incident_update",+ "tableTo": "incident",+ "columnsFrom": [+ "incident_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "incidents_to_monitors": {+ "name": "incidents_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "incident_id": {+ "name": "incident_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "incidents_to_monitors_monitor_id_monitor_id_fk": {+ "name": "incidents_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "incidents_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "incidents_to_monitors_incident_id_incident_id_fk": {+ "name": "incidents_to_monitors_incident_id_incident_id_fk",+ "tableFrom": "incidents_to_monitors",+ "tableTo": "incident",+ "columnsFrom": [+ "incident_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "incidents_to_monitors_monitor_id_incident_id_pk": {+ "columns": [+ "incident_id",+ "monitor_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "page": {+ "name": "page",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "custom_domain": {+ "name": "custom_domain",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "published": {+ "name": "published",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_slug_unique": {+ "name": "page_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "page_workspace_id_workspace_id_fk": {+ "name": "page_workspace_id_workspace_id_fk",+ "tableFrom": "page",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "monitor": {+ "name": "monitor",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "job_type": {+ "name": "job_type",+ "type": "text(3)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "periodicity": {+ "name": "periodicity",+ "type": "text(6)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "status": {+ "name": "status",+ "type": "text(2)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'inactive'"+ },+ "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(512)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_workspace_id_workspace_id_fk": {+ "name": "monitor_workspace_id_workspace_id_fk",+ "tableFrom": "monitor",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "monitors_to_pages": {+ "name": "monitors_to_pages",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitors_to_pages_monitor_id_monitor_id_fk": {+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitors_to_pages_page_id_page_id_fk": {+ "name": "monitors_to_pages_page_id_page_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitors_to_pages_monitor_id_page_id_pk": {+ "columns": [+ "monitor_id",+ "page_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "tenant_id": {+ "name": "tenant_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "first_name": {+ "name": "first_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "last_name": {+ "name": "last_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "photo_url": {+ "name": "photo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "user_tenant_id_unique": {+ "name": "user_tenant_id_unique",+ "columns": [+ "tenant_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "users_to_workspaces": {+ "name": "users_to_workspaces",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "users_to_workspaces_user_id_user_id_fk": {+ "name": "users_to_workspaces_user_id_user_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "users_to_workspaces_workspace_id_workspace_id_fk": {+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "users_to_workspaces_user_id_workspace_id_pk": {+ "columns": [+ "user_id",+ "workspace_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "workspace": {+ "name": "workspace",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stripe_id": {+ "name": "stripe_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "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": {+ "workspace_slug_unique": {+ "name": "workspace_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "workspace_stripe_id_unique": {+ "name": "workspace_stripe_id_unique",+ "columns": [+ "stripe_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ }+ },+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 16f94f9a7..c2c135f22 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -29,6 +29,13 @@"when": 1691614487733,"tag": "0003_glamorous_living_mummy","breakpoints": true+ },+ {+ "idx": 4,+ "version": "5",+ "when": 1691850907670,+ "tag": "0004_fixed_dakota_north",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/schema/monitor.ts b/packages/db/src/schema/monitor.tsindex 67004ad91..ebdedb677 100644--- a/packages/db/src/schema/monitor.ts+++ b/packages/db/src/schema/monitor.ts@@ -56,7 +56,7 @@ export const monitor = sqliteTable("monitor", {workspaceId: integer("workspace_id").references(() => workspace.id),- createdAt: integer("updated_at", { mode: "timestamp" }).default(+ createdAt: integer("created_at", { mode: "timestamp" }).default(sql`(strftime('%s', 'now'))`,),updatedAt: integer("updated_at", { mode: "timestamp" }).default(diff --git a/packages/db/src/schema/page.ts b/packages/db/src/schema/page.tsindex 817578ecf..caf0d2b8b 100644--- a/packages/db/src/schema/page.ts+++ b/packages/db/src/schema/page.ts@@ -25,7 +25,7 @@ export const page = sqliteTable("page", {customDomain: text("custom_domain", { length: 256 }).notNull(),published: integer("published", { mode: "boolean" }).default(false),- createdAt: integer("updated_at", { mode: "timestamp" }).default(+ createdAt: integer("created_at", { mode: "timestamp" }).default(sql`(strftime('%s', 'now'))`,),updatedAt: integer("updated_at", { mode: "timestamp" }).default(diff --git a/packages/db/src/schema/user.ts b/packages/db/src/schema/user.tsindex b0a39e8c5..6aa3c8e48 100644--- a/packages/db/src/schema/user.ts+++ b/packages/db/src/schema/user.ts@@ -17,7 +17,7 @@ export const user = sqliteTable("user", {email: text("email").default(""),photoUrl: text("photo_url").default(""),- createdAt: integer("updated_at", { mode: "timestamp" }).default(+ createdAt: integer("created_at", { mode: "timestamp" }).default(sql`(strftime('%s', 'now'))`,),updatedAt: integer("updated_at", { mode: "timestamp" }).default(diff --git a/packages/db/src/schema/workspace.ts b/packages/db/src/schema/workspace.tsindex ec16fb6c7..72f63c4ec 100644--- a/packages/db/src/schema/workspace.ts+++ b/packages/db/src/schema/workspace.ts@@ -10,7 +10,7 @@ export const workspace = sqliteTable("workspace", {stripeId: text("stripe_id", { length: 256 }).unique(),name: text("name"),- createdAt: integer("updated_at", { mode: "timestamp" }).default(+ createdAt: integer("created_at", { mode: "timestamp" }).default(sql`(strftime('%s', 'now'))`,),updatedAt: integer("updated_at", { mode: "timestamp" }).default(