Skip to content

Open-source status page, incident response and uptime monitoring

fix: soft delete monitor relations (#755)

Maximilian Kaskea57afe801eb8
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index d7eba1eac..997183c03 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -12,6 +12,7 @@ import {
insertMonitorSchema,
monitor,
monitorsToPages,
+ monitorsToStatusReport,
monitorTag,
monitorTagsToMonitors,
notification,
@@ -381,7 +382,20 @@ export const monitorRouter = createTRPCRouter({
.where(eq(monitor.id, monitorToDelete.id))
.run();
- // might delete the notifications and tags related to the monitor
+ await opts.ctx.db.transaction(async (tx) => {
+ await tx
+ .delete(monitorsToPages)
+ .where(eq(monitorsToPages.monitorId, monitorToDelete.id));
+ await tx
+ .delete(monitorTagsToMonitors)
+ .where(eq(monitorTagsToMonitors.monitorId, monitorToDelete.id));
+ await tx
+ .delete(monitorsToStatusReport)
+ .where(eq(monitorsToStatusReport.monitorId, monitorToDelete.id));
+ await tx
+ .delete(notificationsToMonitors)
+ .where(eq(notificationsToMonitors.monitorId, monitorToDelete.id));
+ });
}),
getMonitorsByWorkspace: protectedProcedure.query(async (opts) => {