-- 015_monitored_services.sql
-- DB-backed homelab service registry (replaces the hand-edited config/services.json).
-- Instance-wide (NOT space-scoped — these are infra services, not knowledge resources).
-- Live status stays in service_status, keyed by service_id = monitored_services.id.
CREATE TABLE monitored_services (
  id          text PRIMARY KEY,                       -- stable slug, e.g. 'gitea'
  name        text NOT NULL,
  category    text NOT NULL DEFAULT 'other',
  host        text,
  url         text NOT NULL,
  icon        text,
  check_cfg   jsonb NOT NULL DEFAULT '{}'::jsonb,      -- {type:'http'|'tcp', path?:'/...'}
  source      text NOT NULL DEFAULT 'manual'
              CHECK (source IN ('manual','discovered')),
  enabled     boolean NOT NULL DEFAULT true,
  created_at  timestamptz NOT NULL DEFAULT now(),
  updated_at  timestamptz NOT NULL DEFAULT now()
);
-- Discovery reconciliation looks up by url to avoid re-adding an existing service.
CREATE INDEX idx_monitored_services_url ON monitored_services (url);
