Openstatus www.openstatus.dev
at main 49 lines 1.2 kB view raw
1import { relations, sql } from "drizzle-orm"; 2import { 3 index, 4 integer, 5 primaryKey, 6 sqliteTable, 7 text, 8} from "drizzle-orm/sqlite-core"; 9 10import { monitor, monitorStatus as monitorStatusEnum } from "../monitors"; 11 12export const monitorStatusTable = sqliteTable( 13 "monitor_status", 14 { 15 monitorId: integer("monitor_id") 16 .references(() => monitor.id, { onDelete: "cascade" }) 17 .notNull(), 18 region: text("region").default("").notNull(), 19 status: text("status", { enum: monitorStatusEnum }) 20 .default("active") 21 .notNull(), 22 23 createdAt: integer("created_at", { mode: "timestamp" }).default( 24 sql`(strftime('%s', 'now'))`, 25 ), 26 updatedAt: integer("updated_at", { mode: "timestamp" }).default( 27 sql`(strftime('%s', 'now'))`, 28 ), 29 }, 30 (table) => { 31 return { 32 primaryKey: primaryKey({ columns: [table.monitorId, table.region] }), 33 monitorStatusIdx: index("monitor_status_idx").on( 34 table.monitorId, 35 table.region, 36 ), 37 }; 38 }, 39); 40 41export const monitorStatusRelations = relations( 42 monitorStatusTable, 43 ({ one }) => ({ 44 monitor: one(monitor, { 45 fields: [monitorStatusTable.monitorId], 46 references: [monitor.id], 47 }), 48 }), 49);