2019-10-24 13:04:26 +03:00
|
|
|
package migration_01_to_11
|
|
|
|
|
2019-12-13 05:22:19 +03:00
|
|
|
import (
|
|
|
|
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
|
|
|
)
|
2019-10-24 13:04:26 +03:00
|
|
|
|
|
|
|
var (
|
|
|
|
// metaBucket stores all the meta information concerning the state of
|
|
|
|
// the database.
|
|
|
|
metaBucket = []byte("metadata")
|
|
|
|
|
|
|
|
// dbVersionKey is a boltdb key and it's used for storing/retrieving
|
|
|
|
// current database version.
|
|
|
|
dbVersionKey = []byte("dbp")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Meta structure holds the database meta information.
|
|
|
|
type Meta struct {
|
|
|
|
// DbVersionNumber is the current schema version of the database.
|
|
|
|
DbVersionNumber uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
// putMeta is an internal helper function used in order to allow callers to
|
|
|
|
// re-use a database transaction. See the publicly exported PutMeta method for
|
|
|
|
// more information.
|
2019-12-13 05:22:19 +03:00
|
|
|
func putMeta(meta *Meta, tx kvdb.RwTx) error {
|
|
|
|
metaBucket, err := tx.CreateTopLevelBucket(metaBucket)
|
2019-10-24 13:04:26 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return putDbVersion(metaBucket, meta)
|
|
|
|
}
|
|
|
|
|
2019-12-13 05:22:19 +03:00
|
|
|
func putDbVersion(metaBucket kvdb.RwBucket, meta *Meta) error {
|
2019-10-24 13:04:26 +03:00
|
|
|
scratch := make([]byte, 4)
|
|
|
|
byteOrder.PutUint32(scratch, meta.DbVersionNumber)
|
|
|
|
return metaBucket.Put(dbVersionKey, scratch)
|
|
|
|
}
|