526a78b302
- Extends GetAlbumCoverageRollup's with_art FILTER to include 'theaudiodb' so F's coverage gauge surfaces TheAudioDB-found rows as with_art rather than silently undercounting. - Modifies ListAlbumsMissingCover to take the current sources_version as a parameter; eligibility now includes stale-'none' rows. - Adds SetAlbumCoverWithVersion (atomic write of path + source + version stamp) and the parallel SetArtistArtWithVersion + ClearArtistArtNone + ListArtistsMissingArt for the artist-art enricher. - New coverart_settings.sql with ListProviderSettings, UpsertProviderSettings (boot reconciliation, preserves operator values on conflict), UpdateProviderSettings (admin PATCH; tri- state api_key handling), GetCurrentSourcesVersion, BumpSourcesVersion (RETURNING the new value).
132 lines
3.9 KiB
Go
132 lines
3.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: coverart_settings.sql
|
|
|
|
package dbq
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const bumpSourcesVersion = `-- name: BumpSourcesVersion :one
|
|
UPDATE cover_art_sources_meta
|
|
SET current_version = current_version + 1
|
|
WHERE id = true
|
|
RETURNING current_version
|
|
`
|
|
|
|
// Increments and returns the new version. Called by SettingsService
|
|
// only when the *enabled set* changes (not on key/display_order
|
|
// changes). RETURNING gives the new value back so the handler can
|
|
// include it in the response without a follow-up SELECT.
|
|
func (q *Queries) BumpSourcesVersion(ctx context.Context) (int32, error) {
|
|
row := q.db.QueryRow(ctx, bumpSourcesVersion)
|
|
var current_version int32
|
|
err := row.Scan(¤t_version)
|
|
return current_version, err
|
|
}
|
|
|
|
const getCurrentSourcesVersion = `-- name: GetCurrentSourcesVersion :one
|
|
SELECT current_version FROM cover_art_sources_meta WHERE id = true
|
|
`
|
|
|
|
func (q *Queries) GetCurrentSourcesVersion(ctx context.Context) (int32, error) {
|
|
row := q.db.QueryRow(ctx, getCurrentSourcesVersion)
|
|
var current_version int32
|
|
err := row.Scan(¤t_version)
|
|
return current_version, err
|
|
}
|
|
|
|
const listProviderSettings = `-- name: ListProviderSettings :many
|
|
|
|
SELECT provider_id, enabled, api_key, display_order, created_at, updated_at
|
|
FROM cover_art_provider_settings
|
|
ORDER BY display_order, provider_id
|
|
`
|
|
|
|
// M7 cover-sources: queries for the cover_art_provider_settings table
|
|
// and the cover_art_sources_meta singleton. The SettingsService
|
|
// consumes these.
|
|
// Returns all rows from cover_art_provider_settings. Used by the
|
|
// SettingsService at boot for reconciliation and by the admin GET
|
|
// handler.
|
|
func (q *Queries) ListProviderSettings(ctx context.Context) ([]CoverArtProviderSetting, error) {
|
|
rows, err := q.db.Query(ctx, listProviderSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CoverArtProviderSetting
|
|
for rows.Next() {
|
|
var i CoverArtProviderSetting
|
|
if err := rows.Scan(
|
|
&i.ProviderID,
|
|
&i.Enabled,
|
|
&i.ApiKey,
|
|
&i.DisplayOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateProviderSettings = `-- name: UpdateProviderSettings :exec
|
|
UPDATE cover_art_provider_settings
|
|
SET enabled = COALESCE($2, enabled),
|
|
api_key = CASE WHEN $3::boolean THEN $4 ELSE api_key END,
|
|
updated_at = now()
|
|
WHERE provider_id = $1
|
|
`
|
|
|
|
type UpdateProviderSettingsParams struct {
|
|
ProviderID string
|
|
Enabled bool
|
|
Column3 bool
|
|
ApiKey *string
|
|
}
|
|
|
|
// Admin PATCH applies one or both fields. Pass NULL for enabled to
|
|
// leave it unchanged. Pass FALSE for the apiKeyChanged flag to leave
|
|
// the api_key unchanged regardless of apiKey value; pass TRUE with
|
|
// empty string to clear, or TRUE with non-empty to set.
|
|
func (q *Queries) UpdateProviderSettings(ctx context.Context, arg UpdateProviderSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, updateProviderSettings,
|
|
arg.ProviderID,
|
|
arg.Enabled,
|
|
arg.Column3,
|
|
arg.ApiKey,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const upsertProviderSettings = `-- name: UpsertProviderSettings :exec
|
|
INSERT INTO cover_art_provider_settings (provider_id, enabled, display_order)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (provider_id) DO UPDATE
|
|
SET display_order = EXCLUDED.display_order,
|
|
updated_at = now()
|
|
`
|
|
|
|
type UpsertProviderSettingsParams struct {
|
|
ProviderID string
|
|
Enabled bool
|
|
DisplayOrder int32
|
|
}
|
|
|
|
// INSERT a default row for a newly-registered provider, or update an
|
|
// existing row's display_order on boot reconciliation. Does NOT
|
|
// overwrite enabled / api_key on conflict — the operator's settings
|
|
// persist across restarts.
|
|
func (q *Queries) UpsertProviderSettings(ctx context.Context, arg UpsertProviderSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, upsertProviderSettings, arg.ProviderID, arg.Enabled, arg.DisplayOrder)
|
|
return err
|
|
}
|