Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wtdb: export versions of wtclient.db #9281

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}

// LatestDBMigrationVersion returns the number of the latest existing database
// migration version available.
func LatestDBMigrationVersion() 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
}

// CurrentDatabaseVersion reads the current database version from the database
// and returns it.
func CurrentDatabaseVersion(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
Loading