Rewrites the internal/db/queries comments to rule 32 and regenerates dbq, whose doc comments and embedded SQL carry them. The bugs behind the tiered mixes, the md5 order seed, the score bands and the round-robin arms are restated as the constraint each one enforces; counts from one library and stale cross-references are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.6 KiB
SQL
49 lines
1.6 KiB
SQL
-- Scan-run lifecycle queries.
|
|
|
|
-- name: InsertScanRun :one
|
|
-- Creates a new scan_runs row with started_at=now(). Stages are filled in
|
|
-- as each completes via UpdateScanRunStage; finished_at is set by FinishScanRun.
|
|
INSERT INTO scan_runs DEFAULT VALUES RETURNING id, started_at;
|
|
|
|
-- name: UpdateScanRunLibrary :exec
|
|
-- Persists the file-walk stage's tallies. Idempotent — overwrites prior
|
|
-- value if the orchestrator re-runs the stage on retry.
|
|
UPDATE scan_runs SET library = $2 WHERE id = $1;
|
|
|
|
-- name: UpdateScanRunMbidBackfill :exec
|
|
UPDATE scan_runs SET mbid_backfill = $2 WHERE id = $1;
|
|
|
|
-- name: UpdateScanRunCoverEnrich :exec
|
|
UPDATE scan_runs SET cover_enrich = $2 WHERE id = $1;
|
|
|
|
-- name: FinishScanRun :exec
|
|
-- Closes the row. error_message is non-empty only when a fatal error
|
|
-- aborted the chain before normal completion.
|
|
UPDATE scan_runs
|
|
SET finished_at = now(),
|
|
error_message = NULLIF($2::text, '')
|
|
WHERE id = $1;
|
|
|
|
-- name: GetLatestScanRun :one
|
|
-- Powers GET /api/admin/scan/status. Returns NoRows when no scan has
|
|
-- ever run; the API layer maps that to a 200 with empty payload.
|
|
SELECT id, started_at, finished_at, library, mbid_backfill, cover_enrich, artist_art_enrich, error_message
|
|
FROM scan_runs
|
|
ORDER BY started_at DESC
|
|
LIMIT 1;
|
|
|
|
-- name: UpdateScanRunArtistArtEnrich :exec
|
|
-- Persists the artist-art enrich stage tally JSON.
|
|
UPDATE scan_runs
|
|
SET artist_art_enrich = $2
|
|
WHERE id = $1;
|
|
|
|
-- name: GetInFlightScanRun :one
|
|
-- Used by POST /api/admin/scan/run to 409 when a scan is already running.
|
|
-- "In flight" = finished_at IS NULL.
|
|
SELECT id, started_at
|
|
FROM scan_runs
|
|
WHERE finished_at IS NULL
|
|
ORDER BY started_at DESC
|
|
LIMIT 1;
|