feat: add list controls and DNS check history
This commit is contained in:
parent
11b16ac3cf
commit
24351eb897
14 changed files with 511 additions and 28 deletions
17
packages/db/src/migrations/0003_add_domain_check_history.sql
Normal file
17
packages/db/src/migrations/0003_add_domain_check_history.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
CREATE TABLE IF NOT EXISTS "domain_check_history" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"domain_id" text NOT NULL,
|
||||
"expected_server_ip" text NOT NULL,
|
||||
"status" "domain_resolution_status" NOT NULL,
|
||||
"resolved_ips" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"message" text,
|
||||
"checked_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "domain_check_history" ADD CONSTRAINT "domain_check_history_domain_id_domain_id_fk" FOREIGN KEY ("domain_id") REFERENCES "public"."domain"("id") ON DELETE cascade ON UPDATE no action;
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "domain_check_history_domain_id_idx" ON "domain_check_history" USING btree ("domain_id");
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "domain_check_history_checked_at_idx" ON "domain_check_history" USING btree ("checked_at");
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "domain_check_history_status_idx" ON "domain_check_history" USING btree ("status");
|
||||
|
|
@ -22,6 +22,13 @@
|
|||
"when": 1782698400000,
|
||||
"tag": "0002_user_lifecycle_permissions",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "7",
|
||||
"when": 1786104000000,
|
||||
"tag": "0003_add_domain_check_history",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,6 +121,29 @@ export const domain = pgTable(
|
|||
],
|
||||
);
|
||||
|
||||
export const domainCheckHistory = pgTable(
|
||||
"domain_check_history",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
domainId: text("domain_id")
|
||||
.notNull()
|
||||
.references(() => domain.id, { onDelete: "cascade" }),
|
||||
expectedServerIp: text("expected_server_ip").notNull(),
|
||||
status: domainResolutionStatusEnum("status").notNull(),
|
||||
resolvedIps: jsonb("resolved_ips")
|
||||
.$type<string[]>()
|
||||
.default(sql`'[]'::jsonb`)
|
||||
.notNull(),
|
||||
message: text("message"),
|
||||
checkedAt: timestamp("checked_at").defaultNow().notNull(),
|
||||
},
|
||||
(table) => [
|
||||
index("domain_check_history_domain_id_idx").on(table.domainId),
|
||||
index("domain_check_history_checked_at_idx").on(table.checkedAt),
|
||||
index("domain_check_history_status_idx").on(table.status),
|
||||
],
|
||||
);
|
||||
|
||||
export const note = pgTable(
|
||||
"note",
|
||||
{
|
||||
|
|
@ -153,11 +176,19 @@ export const serviceRelations = relations(service, ({ one, many }) => ({
|
|||
domains: many(domain),
|
||||
}));
|
||||
|
||||
export const domainRelations = relations(domain, ({ one }) => ({
|
||||
export const domainRelations = relations(domain, ({ one, many }) => ({
|
||||
service: one(service, {
|
||||
fields: [domain.serviceId],
|
||||
references: [service.id],
|
||||
}),
|
||||
checks: many(domainCheckHistory),
|
||||
}));
|
||||
|
||||
export const domainCheckHistoryRelations = relations(domainCheckHistory, ({ one }) => ({
|
||||
domain: one(domain, {
|
||||
fields: [domainCheckHistory.domainId],
|
||||
references: [domain.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const noteRelations = relations(note, ({ one }) => ({
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ dotenv.config({
|
|||
|
||||
import { db } from "./index";
|
||||
import { account, permission, role, rolePermission, user, userRole } from "./schema/auth";
|
||||
import { domain, note, server, service } from "./schema/monitoring";
|
||||
import { domain, domainCheckHistory, note, server, service } from "./schema/monitoring";
|
||||
|
||||
const now = new Date();
|
||||
const earlierToday = new Date(now.getTime() - 45 * 60 * 1000);
|
||||
|
|
@ -293,6 +293,20 @@ async function seedMonitoringData() {
|
|||
})),
|
||||
);
|
||||
|
||||
await db.insert(domainCheckHistory).values(
|
||||
domains
|
||||
.filter((item) => item.lastCheckedAt)
|
||||
.map((item) => ({
|
||||
id: `history_${item.id}`,
|
||||
domainId: item.id,
|
||||
expectedServerIp: item.expectedServerIp,
|
||||
status: item.resolutionStatus,
|
||||
resolvedIps: item.lastResolvedIps,
|
||||
message: item.lastCheckMessage,
|
||||
checkedAt: item.lastCheckedAt,
|
||||
})),
|
||||
);
|
||||
|
||||
await db.insert(note).values(
|
||||
notes.map((item) => ({
|
||||
...item,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue