diff --git a/internal/db/migrations/0017_scan_runs.down.sql b/internal/db/migrations/0017_scan_runs.down.sql new file mode 100644 index 00000000..a498146a --- /dev/null +++ b/internal/db/migrations/0017_scan_runs.down.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS scan_runs_started_at_idx; +DROP TABLE IF EXISTS scan_runs; diff --git a/internal/db/migrations/0017_scan_runs.up.sql b/internal/db/migrations/0017_scan_runs.up.sql new file mode 100644 index 00000000..e17f4048 --- /dev/null +++ b/internal/db/migrations/0017_scan_runs.up.sql @@ -0,0 +1,20 @@ +-- M7 #381: track library-scan / MBID-backfill / cover-enrich runs so the +-- admin overview can show last-run results + manual trigger state. +CREATE TABLE scan_runs ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + started_at timestamptz NOT NULL DEFAULT now(), + finished_at timestamptz, + -- Per-stage tallies are jsonb so the schema doesn't need to grow when + -- a stage gains/loses a counter. Each stage's value matches the Go + -- struct emitted by that worker (e.g. library.Stats). + library jsonb, + mbid_backfill jsonb, + cover_enrich jsonb, + -- Non-empty when the run as a whole errored (a stage panic, or the + -- worker hit a fatal error before writing stage tallies). + error_message text +); + +-- The status endpoint always reads the latest row; the in-flight guard +-- needs to find rows where finished_at IS NULL. Both hit started_at DESC. +CREATE INDEX scan_runs_started_at_idx ON scan_runs (started_at DESC);