feat(admin): metadata-profile picker on integrations page

Persists the operator's metadata-profile choice alongside quality
profile + root folder. Defaults to the first profile Lidarr returns
(usually 'Standard' on a vanilla install) so the common case is
zero-click; operators with custom profiles like 'Singles only' can pick
explicitly.

Backend:
- Migration 0013: adds nullable default_metadata_profile_id to
  lidarr_config. Existing rows get NULL and the service falls back to
  fetch-and-pick-first until they save.
- Updated lidarr_config queries + sqlc + lidarrconfig.Config + admin
  view/put body to round-trip the new field.
- handlePutLidarrConfig requires it (along with QP and root folder)
  when enabled=true — matches the existing missing_defaults gate.
- New GET /api/admin/lidarr/metadata-profiles handler + lidarr.Client
  ListMetadataProfiles (GET /api/v1/metadataprofile, same shape as
  the quality-profile endpoint).
- lidarrrequests.Approve prefers cfg.DefaultMetadataProfileID; falls
  back to the fetch-list path only when 0 (back-compat for upgraders).

Frontend:
- LidarrConfig type + LidarrMetadataProfile type + qk.lidarrMetadataProfiles.
- listMetadataProfiles + createMetadataProfilesQuery client helpers.
- Integrations page: third <select> picker, auto-defaults to first
  profile when the saved value is 0, sends the new field on save and
  clears it on disconnect.
- Updated test fixtures + the duplicate 'Standard' option string in
  the dropdown-populates assertion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 00:09:13 -04:00
parent 7d33166f23
commit c265b871c3
15 changed files with 236 additions and 85 deletions
+50 -17
View File
@@ -7,24 +7,40 @@ package dbq
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getLidarrConfig = `-- name: GetLidarrConfig :one
SELECT id, enabled, base_url, api_key, default_quality_profile_id,
default_root_folder_path, created_at, updated_at
default_metadata_profile_id, default_root_folder_path,
created_at, updated_at
FROM lidarr_config
WHERE id = 1
`
func (q *Queries) GetLidarrConfig(ctx context.Context) (LidarrConfig, error) {
type GetLidarrConfigRow struct {
ID int16
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultMetadataProfileID *int32
DefaultRootFolderPath *string
CreatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
}
func (q *Queries) GetLidarrConfig(ctx context.Context) (GetLidarrConfigRow, error) {
row := q.db.QueryRow(ctx, getLidarrConfig)
var i LidarrConfig
var i GetLidarrConfigRow
err := row.Scan(
&i.ID,
&i.Enabled,
&i.BaseUrl,
&i.ApiKey,
&i.DefaultQualityProfileID,
&i.DefaultMetadataProfileID,
&i.DefaultRootFolderPath,
&i.CreatedAt,
&i.UpdatedAt,
@@ -34,40 +50,57 @@ func (q *Queries) GetLidarrConfig(ctx context.Context) (LidarrConfig, error) {
const updateLidarrConfig = `-- name: UpdateLidarrConfig :one
UPDATE lidarr_config
SET enabled = $1,
base_url = $2,
api_key = $3,
default_quality_profile_id = $4,
default_root_folder_path = $5,
updated_at = now()
SET enabled = $1,
base_url = $2,
api_key = $3,
default_quality_profile_id = $4,
default_metadata_profile_id = $5,
default_root_folder_path = $6,
updated_at = now()
WHERE id = 1
RETURNING id, enabled, base_url, api_key, default_quality_profile_id,
default_root_folder_path, created_at, updated_at
default_metadata_profile_id, default_root_folder_path,
created_at, updated_at
`
type UpdateLidarrConfigParams struct {
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultRootFolderPath *string
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultMetadataProfileID *int32
DefaultRootFolderPath *string
}
func (q *Queries) UpdateLidarrConfig(ctx context.Context, arg UpdateLidarrConfigParams) (LidarrConfig, error) {
type UpdateLidarrConfigRow struct {
ID int16
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultMetadataProfileID *int32
DefaultRootFolderPath *string
CreatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
}
func (q *Queries) UpdateLidarrConfig(ctx context.Context, arg UpdateLidarrConfigParams) (UpdateLidarrConfigRow, error) {
row := q.db.QueryRow(ctx, updateLidarrConfig,
arg.Enabled,
arg.BaseUrl,
arg.ApiKey,
arg.DefaultQualityProfileID,
arg.DefaultMetadataProfileID,
arg.DefaultRootFolderPath,
)
var i LidarrConfig
var i UpdateLidarrConfigRow
err := row.Scan(
&i.ID,
&i.Enabled,
&i.BaseUrl,
&i.ApiKey,
&i.DefaultQualityProfileID,
&i.DefaultMetadataProfileID,
&i.DefaultRootFolderPath,
&i.CreatedAt,
&i.UpdatedAt,
+9 -8
View File
@@ -254,14 +254,15 @@ type GeneralLikesArtist struct {
}
type LidarrConfig struct {
ID int16
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultRootFolderPath *string
CreatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
ID int16
Enabled bool
BaseUrl *string
ApiKey *string
DefaultQualityProfileID *int32
DefaultRootFolderPath *string
CreatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
DefaultMetadataProfileID *int32
}
type LidarrQuarantine struct {
@@ -0,0 +1,2 @@
ALTER TABLE lidarr_config
DROP COLUMN default_metadata_profile_id;
@@ -0,0 +1,9 @@
-- M6a follow-up: persist the operator's metadata-profile choice alongside
-- quality profile + root folder. Lidarr POST /api/v1/artist requires
-- metadataProfileId; without storing it we'd refetch and pick first on
-- every Approve, denying the operator a choice. Nullable: existing rows
-- (and operators upgrading from before this migration) get NULL and the
-- service falls back to "fetch list and pick first" until they save.
ALTER TABLE lidarr_config
ADD COLUMN default_metadata_profile_id integer;
+11 -8
View File
@@ -1,17 +1,20 @@
-- name: GetLidarrConfig :one
SELECT id, enabled, base_url, api_key, default_quality_profile_id,
default_root_folder_path, created_at, updated_at
default_metadata_profile_id, default_root_folder_path,
created_at, updated_at
FROM lidarr_config
WHERE id = 1;
-- name: UpdateLidarrConfig :one
UPDATE lidarr_config
SET enabled = $1,
base_url = $2,
api_key = $3,
default_quality_profile_id = $4,
default_root_folder_path = $5,
updated_at = now()
SET enabled = $1,
base_url = $2,
api_key = $3,
default_quality_profile_id = $4,
default_metadata_profile_id = $5,
default_root_folder_path = $6,
updated_at = now()
WHERE id = 1
RETURNING id, enabled, base_url, api_key, default_quality_profile_id,
default_root_folder_path, created_at, updated_at;
default_metadata_profile_id, default_root_folder_path,
created_at, updated_at;