Skip to content

Commit e1df8e9

Browse files
authored
Merge pull request #9281 from ziggie1984/export-towerclientdb-version
wtdb: export versions of wtclient.db
2 parents 9519a23 + aaa0abc commit e1df8e9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

watchtower/wtdb/version.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func getLatestDBVersion(versions []version) uint32 {
7878
return uint32(len(versions))
7979
}
8080

81+
// LatestDBMigrationVersion returns the number of the latest existing database
82+
// migration version available.
83+
func LatestDBMigrationVersion() uint32 {
84+
return getLatestDBVersion(clientDBVersions)
85+
}
86+
8187
// getMigrations returns a slice of all updates with a greater number that
8288
// curVersion that need to be applied to sync up with the latest version.
8389
func getMigrations(versions []version, curVersion uint32) []version {
@@ -91,6 +97,27 @@ func getMigrations(versions []version, curVersion uint32) []version {
9197
return updates
9298
}
9399

100+
// CurrentDatabaseVersion reads the current database version from the database
101+
// and returns it.
102+
func CurrentDatabaseVersion(db kvdb.Backend) (uint32, error) {
103+
var (
104+
version uint32
105+
err error
106+
)
107+
108+
err = kvdb.View(db, func(tx kvdb.RTx) error {
109+
version, err = getDBVersion(tx)
110+
return err
111+
}, func() {
112+
version = 0
113+
})
114+
if err != nil {
115+
return 0, err
116+
}
117+
118+
return version, nil
119+
}
120+
94121
// getDBVersion retrieves the current database version from the metadata bucket
95122
// using the dbVersionKey.
96123
func getDBVersion(tx kvdb.RTx) (uint32, error) {

0 commit comments

Comments
 (0)