feat(health): add external URL column, backfill domains, thread through repo

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-08 00:54:10 +10:00
parent 276889e7fe
commit 789dc2442e
3 changed files with 34 additions and 9 deletions

View File

@@ -1,12 +1,12 @@
import { pool } from '../pool.js';
const COLS = 'id, name, category, host, url, icon, check_cfg, source, enabled';
const COLS = 'id, name, category, host, url, icon, external, check_cfg, source, enabled';
// Map a DB row to the service shape the registry/checker expect (check_cfg -> check).
function toSvc(r) {
return {
id: r.id, name: r.name, category: r.category, host: r.host, url: r.url,
icon: r.icon, check: r.check_cfg || {}, source: r.source, enabled: r.enabled
icon: r.icon, external: r.external ?? null, check: r.check_cfg || {}, source: r.source, enabled: r.enabled
};
}
@@ -42,15 +42,15 @@ export async function count() {
export async function create(svc) {
const { id, name, category = 'other', host = null, url, icon = null,
check = {}, source = 'manual', enabled = true } = svc;
external = null, check = {}, source = 'manual', enabled = true } = svc;
const { rows: [r] } = await pool.query(
`INSERT INTO monitored_services (id, name, category, host, url, icon, check_cfg, source, enabled)
VALUES ($1,$2,$3,$4,$5,$6,$7::jsonb,$8,$9) RETURNING ${COLS}`,
[id, name, category, host, url, icon, JSON.stringify(check), source, enabled]);
`INSERT INTO monitored_services (id, name, category, host, url, icon, external, check_cfg, source, enabled)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8::jsonb,$9,$10) RETURNING ${COLS}`,
[id, name, category, host, url, icon, external, JSON.stringify(check), source, enabled]);
return toSvc(r);
}
const PATCHABLE = ['name', 'category', 'host', 'url', 'icon', 'enabled'];
const PATCHABLE = ['name', 'category', 'host', 'url', 'icon', 'external', 'enabled'];
export async function update(id, patch) {
const sets = [], vals = [];
for (const k of PATCHABLE) {
@@ -75,8 +75,8 @@ export async function remove(id) {
export async function upsertDiscovered(svc) {
const { id, name, category = 'other', host = null, url, icon = null, check = {} } = svc;
const { rows: [r] } = await pool.query(
`INSERT INTO monitored_services (id, name, category, host, url, icon, check_cfg, source, enabled)
SELECT $1,$2,$3,$4,$5,$6,$7::jsonb,'discovered',false
`INSERT INTO monitored_services (id, name, category, host, url, icon, external, check_cfg, source, enabled)
SELECT $1,$2,$3,$4,$5,$6,NULL,$7::jsonb,'discovered',false
WHERE NOT EXISTS (SELECT 1 FROM monitored_services WHERE url=$5)
ON CONFLICT (id) DO NOTHING
RETURNING ${COLS}`,