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:
1 parent
faebc5dfb0
commit
c8e7d14677
2 files changed
+60
-3
No files matched your search
@@ -2,6 +2,8 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -57,3 +59,45 @@ func TestMatchLetters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Databases reached schema 11 two ways: the removed "missing from master"
|
||||
// column, or (briefly) auto_cleanup_empty numbered 11. Both must open with
|
||||
// every current column, keeping their pairs.
|
||||
func TestMigrateFromEitherSchema11(t *testing.T) {
|
||||
for name, eleven := range map[string]string{
|
||||
"missing": `ALTER TABLE matches ADD COLUMN missing TEXT NOT NULL DEFAULT '';`,
|
||||
"auto cleanup": `ALTER TABLE pairs ADD COLUMN auto_cleanup_empty INTEGER NOT NULL DEFAULT 0;`,
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
db, err := sql.Open("sqlite", "file:"+filepath.Join(dir, "playlink.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := append(append([]string{}, migrations[:10]...), eleven,
|
||||
`INSERT INTO pairs (name, master_root, slave_root, quarantine_dir, extensions, created_at) VALUES ('Music', '/m', '/s', '/q', 'flac', 1)`)
|
||||
stmts := []string{`CREATE TABLE schema_version (v INTEGER NOT NULL)`, `INSERT INTO schema_version (v) VALUES (11)`}
|
||||
for _, m := range append(stmts, old...) {
|
||||
if _, err := db.Exec(m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
db.Close()
|
||||
|
||||
st, err := Open(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer st.DB.Close()
|
||||
ps, err := st.Pairs(context.Background())
|
||||
if err != nil || len(ps) != 1 || ps[0].Name != "Music" {
|
||||
t.Fatalf("pairs = %+v, %v", ps, err)
|
||||
}
|
||||
var v int
|
||||
st.DB.QueryRow(`SELECT MAX(v) FROM schema_version`).Scan(&v)
|
||||
if v != SchemaVersion() {
|
||||
t.Fatalf("schema %d, want %d", v, SchemaVersion())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user