Skip to content

Commit

Permalink
wtdb: export versions of wtclient.db
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggie1984 committed Nov 19, 2024
1 parent d14f4c7 commit 5c8f430
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions watchtower/wtdb/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func getLatestDBVersion(versions []version) uint32 {
return uint32(len(versions))
}

// LatestDBVersion returns the number of the latest database version currently
// known to the wtclient.db.
func LatestDBVersion() uint32 {
return getLatestDBVersion(clientDBVersions)
}

// getMigrations returns a slice of all updates with a greater number that
// curVersion that need to be applied to sync up with the latest version.
func getMigrations(versions []version, curVersion uint32) []version {
Expand All @@ -91,6 +97,27 @@ func getMigrations(versions []version, curVersion uint32) []version {
return updates
}

// GetLatestDBVersion returns the number of the latest database version
// currently known to the wtclient.db.
func GetLatestDBVersion(db kvdb.Backend) (uint32, error) {
var (
version uint32
err error
)

err = kvdb.View(db, func(tx kvdb.RTx) error {
version, err = getDBVersion(tx)
return err
}, func() {
version = 0
})
if err != nil {
return 0, err
}

return version, nil
}

// getDBVersion retrieves the current database version from the metadata bucket
// using the dbVersionKey.
func getDBVersion(tx kvdb.RTx) (uint32, error) {
Expand Down

0 comments on commit 5c8f430

Please sign in to comment.