Skip to content

Commit

Permalink
Merge pull request #150 from AndreasSko/v14_again
Browse files Browse the repository at this point in the history
Support schema version 14 again 🙃
  • Loading branch information
AndreasSko authored Sep 1, 2023
2 parents 2111e30 + 19baad7 commit 73132d8
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion model/Database.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (db *Database) ImportJWLBackup(filename string) error {

// Make sure that we support this backup version
if err := manifest.validateManifest(); err != nil {
return err
return fmt.Errorf("backup incompatible: %w", err)
}

// Fill the Database with actual data
Expand Down
2 changes: 1 addition & 1 deletion model/Database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ func Test_createEmptySQLiteDB(t *testing.T) {
}
hash := fmt.Sprintf("%x", hasher.Sum(nil))

assert.Equal(t, "774af7240646c49f6a55e40b6cdf681a6b04fbcf4acebdb19a6e0e2bef53d766", hash)
assert.Equal(t, "78edd07c0b04212dcc2dd59be0a5d2edf91088136986378147cd8aa04cf4965c", hash)
}

func TestDatabase_saveToNewSQLite(t *testing.T) {
Expand Down
Binary file modified model/data/userData.db
Binary file not shown.
2 changes: 1 addition & 1 deletion model/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const version = 1
const schemaVersion = 13
const schemaVersion = 14

type manifest struct {
CreationDate string `json:"creationDate"`
Expand Down
21 changes: 11 additions & 10 deletions model/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
Expand All @@ -16,7 +17,7 @@ var exampleManifest = &manifest{
LastModifiedDate: time.Now().Format("2006-01-02T15:04:05-07:00"),
Hash: "e2e09ceba668bb1ad093b2db317237451a01ae9ff435b38c840b70dc434f184f",
DatabaseName: userDataFilename,
SchemaVersion: 13,
SchemaVersion: 14,
DeviceName: "go-jwlm",
},
Name: "test",
Expand All @@ -36,7 +37,7 @@ func Test_manifest_importManifest(t *testing.T) {
LastModifiedDate: "2020-04-09T05:47:26+02:00",
Hash: "d87a67028133cc4de5536affe1b072841def95899b7f7450a5622112b4b5e63f",
DatabaseName: userDataFilename,
SchemaVersion: 13,
SchemaVersion: 14,
DeviceName: "iPhone",
},
Name: "UserDataBackup_2020-04-11_iPhone",
Expand Down Expand Up @@ -71,7 +72,7 @@ func Test_manifest_validateManifest2(t *testing.T) {
name: "All good",
mfst: &manifest{
UserDataBackup: userDataBackup{
SchemaVersion: 13,
SchemaVersion: 14,
},
Version: 1,
},
Expand All @@ -81,7 +82,7 @@ func Test_manifest_validateManifest2(t *testing.T) {
name: "Manifest version too old",
mfst: &manifest{
UserDataBackup: userDataBackup{
SchemaVersion: 13,
SchemaVersion: 14,
},
Version: 0,
},
Expand All @@ -93,7 +94,7 @@ func Test_manifest_validateManifest2(t *testing.T) {
name: "Manifest version too new",
mfst: &manifest{
UserDataBackup: userDataBackup{
SchemaVersion: 13,
SchemaVersion: 14,
},
Version: 2,
},
Expand All @@ -105,24 +106,24 @@ func Test_manifest_validateManifest2(t *testing.T) {
name: "Schema version too old",
mfst: &manifest{
UserDataBackup: userDataBackup{
SchemaVersion: 12,
SchemaVersion: 13,
},
Version: 1,
},
wantErr: func(tt assert.TestingT, err error, i ...interface{}) bool {
return assert.ErrorContains(tt, err, "schema version is too old. Should be 13 is 12")
return assert.ErrorContains(tt, err, "schema version is too old. Should be 14 is 13")
},
},
{
name: "Schema version too new",
mfst: &manifest{
UserDataBackup: userDataBackup{
SchemaVersion: 14,
SchemaVersion: 15,
},
Version: 1,
},
wantErr: func(tt assert.TestingT, err error, i ...interface{}) bool {
return assert.ErrorContains(tt, err, "schema version is too new. Should be 13 is 14")
return assert.ErrorContains(tt, err, "schema version is too new. Should be 14 is 15")
},
},
}
Expand All @@ -149,7 +150,7 @@ func Test_generateManifest(t *testing.T) {
func Test_exportManifest(t *testing.T) {
tmp, err := ioutil.TempDir("", "go-jwlm")
assert.NoError(t, err)
//defer os.RemoveAll(tmp)
defer os.RemoveAll(tmp)

path := filepath.Join(tmp, "test_manifest.json")
fmt.Println(path)
Expand Down
Binary file modified model/testdata/backup.jwlibrary
Binary file not shown.
Binary file modified model/testdata/backup_shuffled.jwlibrary
Binary file not shown.
Binary file modified model/testdata/backup_withPlaylist.jwlibrary
Binary file not shown.
2 changes: 1 addition & 1 deletion model/testdata/manifest_correct.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lastModifiedDate": "2020-04-09T05:47:26+02:00",
"hash": "d87a67028133cc4de5536affe1b072841def95899b7f7450a5622112b4b5e63f",
"databaseName": "userData.db",
"schemaVersion": 13,
"schemaVersion": 14,
"deviceName": "iPhone"
},
"name": "UserDataBackup_2020-04-11_iPhone",
Expand Down
2 changes: 1 addition & 1 deletion model/testdata/manifest_outdated.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lastModifiedDate": "2020-04-09T05:47:26+02:00",
"hash": "d87a67028133cc4de5536affe1b072841def95899b7f7450a5622112b4b5e63f",
"databaseName": "user_data.db",
"schemaVersion": 8,
"schemaVersion": 13,
"deviceName": "iPhone"
},
"name": "UserDataBackup_2020-04-11_iPhone",
Expand Down

0 comments on commit 73132d8

Please sign in to comment.