Many to one on sites and health checks

This commit is contained in:
Owen
2026-04-15 14:58:33 -07:00
parent f379986a59
commit bf64e226d3
6 changed files with 326 additions and 86 deletions

View File

@@ -471,11 +471,6 @@ export const alertRules = sqliteTable("alertRules", {
| "health_check_not_healthy"
>()
.notNull(),
siteId: integer("siteId").references(() => sites.siteId, { onDelete: "cascade" }),
healthCheckId: integer("healthCheckId").references(
() => targetHealthCheck.targetHealthCheckId,
{ onDelete: "cascade" }
),
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
cooldownSeconds: integer("cooldownSeconds").notNull().default(300),
lastTriggeredAt: integer("lastTriggeredAt"),
@@ -483,6 +478,26 @@ export const alertRules = sqliteTable("alertRules", {
updatedAt: integer("updatedAt").notNull()
});
export const alertSites = sqliteTable("alertSites", {
alertRuleId: integer("alertRuleId")
.notNull()
.references(() => alertRules.alertRuleId, { onDelete: "cascade" }),
siteId: integer("siteId")
.notNull()
.references(() => sites.siteId, { onDelete: "cascade" })
});
export const alertHealthChecks = sqliteTable("alertHealthChecks", {
alertRuleId: integer("alertRuleId")
.notNull()
.references(() => alertRules.alertRuleId, { onDelete: "cascade" }),
healthCheckId: integer("healthCheckId")
.notNull()
.references(() => targetHealthCheck.targetHealthCheckId, {
onDelete: "cascade"
})
});
export const alertEmailActions = sqliteTable("alertEmailActions", {
emailActionId: integer("emailActionId").primaryKey({ autoIncrement: true }),
alertRuleId: integer("alertRuleId")