Skip to content
Snippets Groups Projects
Commit e0c3f9c5 authored by Jake Taylor's avatar Jake Taylor
Browse files

fix indexedDb migration code

parent f9091a63
Branches
Tags
1 merge request!60Revert "Fail a test to be sure it works"
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"syscall/js" "syscall/js"
"github.com/hack-pad/go-indexeddb/idb" "github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/channels" "gitlab.com/elixxir/client/channels"
...@@ -27,7 +26,7 @@ const ( ...@@ -27,7 +26,7 @@ const (
// currentVersion is the current version of the IndexDb // currentVersion is the current version of the IndexDb
// runtime. Used for migration purposes. // runtime. Used for migration purposes.
currentVersion uint = 1 currentVersion uint = 2
) )
// MessageReceivedCallback is called any time a message is received or updated // MessageReceivedCallback is called any time a message is received or updated
...@@ -62,19 +61,24 @@ func newWASMModel(databaseName string, cb MessageReceivedCallback) ( ...@@ -62,19 +61,24 @@ func newWASMModel(databaseName string, cb MessageReceivedCallback) (
openRequest, _ := idb.Global().Open(ctx, databaseName, currentVersion, openRequest, _ := idb.Global().Open(ctx, databaseName, currentVersion,
func(db *idb.Database, oldVersion, newVersion uint) error { func(db *idb.Database, oldVersion, newVersion uint) error {
if oldVersion == newVersion { if oldVersion == newVersion {
jww.INFO.Printf("IndexDb version is current: v%d", newVersion) jww.INFO.Printf("IndexDb version is current: v%d",
newVersion)
return nil return nil
} }
jww.INFO.Printf( jww.INFO.Printf("IndexDb upgrade required: v%d -> v%d",
"IndexDb upgrade required: v%d -> v%d", oldVersion, newVersion) oldVersion, newVersion)
if oldVersion == 0 && newVersion == 1 { if oldVersion == 0 && newVersion >= 1 {
return v1Upgrade(db) err := v1Upgrade(db)
if err != nil {
return err
}
oldVersion = 1
} }
return errors.Errorf("Invalid version upgrade path: v%d -> v%d", // if oldVersion == 1 && newVersion >= 2 { v2Upgrade(), oldVersion = 2 }
oldVersion, newVersion) return nil
}) })
// Wait for database open to finish // Wait for database open to finish
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment