Skip to content
Snippets Groups Projects
Select Git revision
  • 9d61542a211dcee6752079e6f2899b369a85dda5
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

drng_test.go

Blame
  • versioning.go 1.25 KiB
    package database
    
    import (
    	"errors"
    	"fmt"
    
    	"github.com/iotaledger/hive.go/kvstore"
    )
    
    const (
    	// DBVersion defines the version of the database schema this version of GoShimmer supports.
    	// Every time there's a breaking change regarding the stored data, this version flag should be adjusted.
    	DBVersion = 2
    )
    
    var (
    	// ErrDBVersionIncompatible is returned when the database has an unexpected version.
    	ErrDBVersionIncompatible = errors.New("database version is not compatible. please delete your database folder and restart")
    	// the key under which the database is stored
    	dbVersionKey = []byte{0}
    )
    
    // checks whether the database is compatible with the current schema version.
    // also automatically sets the version if the database is new.
    func checkDatabaseVersion(store kvstore.KVStore) error {
    	entry, err := store.Get(dbVersionKey)
    	if err == kvstore.ErrKeyNotFound {
    		// set the version in an empty DB
    		return store.Set(dbVersionKey, []byte{DBVersion})
    	}
    	if err != nil {
    		return err
    	}
    	if len(entry) == 0 {
    		return fmt.Errorf("%w: no database version was persisted", ErrDBVersionIncompatible)
    	}
    	if entry[0] != DBVersion {
    		return fmt.Errorf("%w: supported version: %d, version of database: %d", ErrDBVersionIncompatible, DBVersion, entry[0])
    	}
    	return nil
    }