-- 0015_jobs_source_group_id.sql
--
-- Add source_group_id to jobs so the alert engine can dedup
-- backup/forget/prune/check failures per source group rather than
-- collapsing every failed thing on a host onto one open alert per
-- kind. Backup jobs always have one set (each group is its own
-- restic invocation); forget/prune/check are repo-scoped and leave
-- it NULL.
--
-- Column-level ALTER is safe under foreign_keys=ON (CLAUDE.md). The
-- existing rebuild pattern in 0012 should not be repeated here.

ALTER TABLE jobs ADD COLUMN source_group_id TEXT
    REFERENCES source_groups(id) ON DELETE SET NULL;

CREATE INDEX jobs_source_group_id ON jobs(source_group_id);
