From d0fbba14ff7dd456157ffb8a2d5d860a97f63fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Thu, 12 Mar 2026 11:39:31 -0400 Subject: [PATCH] fix(db): check both name and target_format in default transcodings migration (#5175) The ensure_default_transcodings migration only checked target_format before inserting, but the transcoding table has UNIQUE constraints on both name and target_format. Older installations may have entries where the name matches a default (e.g., 'opus audio') but the target_format differs (e.g., 'oga' instead of 'opus'), causing a UNIQUE constraint violation on name during the INSERT. Fixes #5174 --- db/migrations/20260309203355_ensure_default_transcodings.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/migrations/20260309203355_ensure_default_transcodings.go b/db/migrations/20260309203355_ensure_default_transcodings.go index ff383822..ab6d2495 100644 --- a/db/migrations/20260309203355_ensure_default_transcodings.go +++ b/db/migrations/20260309203355_ensure_default_transcodings.go @@ -17,9 +17,12 @@ func upEnsureDefaultTranscodings(_ context.Context, tx *sql.Tx) error { // Older installations may be missing default transcodings that were added // after the initial seeding (e.g., aac was added later than mp3/opus). // Insert any missing defaults without touching user-customized entries. + // Check both target_format and name since both have UNIQUE constraints, + // and older entries may have a different target_format (e.g., 'oga' vs 'opus') + // but the same name. for _, t := range consts.DefaultTranscodings { var count int - err := tx.QueryRow("SELECT COUNT(*) FROM transcoding WHERE target_format = ?", t.TargetFormat).Scan(&count) + err := tx.QueryRow("SELECT COUNT(*) FROM transcoding WHERE target_format = ? OR name = ?", t.TargetFormat, t.Name).Scan(&count) if err != nil { return err }