File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff 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.
8389func 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.
96123func getDBVersion (tx kvdb.RTx ) (uint32 , error ) {
You can’t perform that action at this time.
0 commit comments