Fix pairs disappearing: renumber the auto-cleanup migration to 12

The reverted "missing from master" feature had shipped migration 11, so
databases that ran it skipped the new auto_cleanup_empty migration (also
11) and every pairs query failed, showing no libraries. Restore the old
11 as an unused placeholder like 6-10 and add the column as 12; a
database that ran it under the old number counts it as applied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-10-08 15:44:57 -07:00
1 parent faebc5dfb0
commit c8e7d14677
2 files changed
+60 -3

No files matched your search

+16 -3
View File
@@ -6,6 +6,7 @@ import (
"database/sql"
"fmt"
"path/filepath"
"strings"
"time"
_ "modernc.org/sqlite"
@@ -119,7 +120,7 @@ var migrations = []string{
// undo must then leave that target alone.
`ALTER TABLE operations ADD COLUMN link_preexisted INTEGER NOT NULL DEFAULT 0;`,
// 6-10 belong to features that were removed again (tag editing,
// 6-11 belong to features that were removed again (tag editing,
// organizing, the step-by-step fixer). They only add columns, which are
// unused now, and stay so databases that already ran them keep the same
// numbering and future migrations are never skipped.
@@ -141,10 +142,22 @@ var migrations = []string{
`ALTER TABLE pairs ADD COLUMN library_type TEXT NOT NULL DEFAULT 'music';
ALTER TABLE pairs ADD COLUMN fixer_state TEXT NOT NULL DEFAULT '';`,
// 11: opt-in automatic removal of empty slave folders after each scan.
// 11: slave-only songs whose album or artist the master has (removed).
`ALTER TABLE matches ADD COLUMN missing TEXT NOT NULL DEFAULT '';`,
// 12: opt-in automatic removal of empty slave folders after each scan.
// For a few hours this was numbered 11, so databases that ran it under
// that number already have the column; see addsExistingColumn.
`ALTER TABLE pairs ADD COLUMN auto_cleanup_empty INTEGER NOT NULL DEFAULT 0;`,
}
// addsExistingColumn reports whether a migration failed only because the
// single column it adds is already there, so it counts as applied.
func addsExistingColumn(m string, err error) bool {
return strings.Count(strings.TrimSpace(m), ";") == 1 && strings.Contains(m, "ADD COLUMN") &&
strings.Contains(err.Error(), "duplicate column name")
}
// SchemaVersion is the newest database schema this build knows.
func SchemaVersion() int { return len(migrations) }
@@ -178,7 +191,7 @@ func (s *Store) migrate() error {
if err != nil {
return err
}
if _, err := tx.Exec(migrations[i]); err != nil {
if _, err := tx.Exec(migrations[i]); err != nil && !addsExistingColumn(migrations[i], err) {
tx.Rollback()
return fmt.Errorf("migration %d: %w", i+1, err)
}