feat(10-01): implement migration 6 and pre-migration backup

- Add backupDatabase() for timestamped .db file backup before migration
- Add migration6MultiLibrary() with all 14 steps: FK OFF, create libraries table,
  insert default library from TOML config, add library_id to audio_files, rebuild
  playlist_tracks with SET NULL FK and 6 phantom columns, backfill phantom metadata,
  recreate track_metadata VIEW with library_id, FK ON, clean TOML config
- Add readLibraryDirFromTOML() and removeLibraryDirFromTOML() helpers
- Update runMigrations signature to accept dbPath for backup
- Add sentinel library row in NewTestDB for FK constraint satisfaction
This commit is contained in:
2026-03-09 09:41:08 -04:00
parent 535855b383
commit 1179f56c36
2 changed files with 506 additions and 2 deletions
+10 -1
View File
@@ -57,10 +57,19 @@ func NewTestDB(t *testing.T) *DB {
}
}
if err := runMigrations(ctx, db, slog.Default()); err != nil {
if err := runMigrations(ctx, db, slog.Default(), ":memory:"); err != nil {
t.Fatalf("could not run migrations: %v", err)
}
// Insert a sentinel library row at id=0 so audio_files inserts
// using the DEFAULT library_id=0 satisfy the FK constraint.
if _, err := db.ExecContext(
ctx,
"INSERT INTO libraries (id, name, path) VALUES (0, 'Test', '/test')",
); err != nil {
t.Fatalf("could not insert test library: %v", err)
}
queries := sqlcgen.New(db)
t.Cleanup(func() { _ = db.Close() })