AllDatabases now returns the current database version of any database: e.g. if mydb/foo is in use, we return a revision db on branch foo for mydb (instead of mydb/main)

This commit is contained in:
Zach Musgrave
2023-06-01 10:04:43 -07:00
parent 2a8d7ac831
commit 76ca92ea2d

View File

@@ -255,12 +255,27 @@ func (p DoltDatabaseProvider) HasDatabase(ctx *sql.Context, name string) bool {
}
func (p DoltDatabaseProvider) AllDatabases(ctx *sql.Context) (all []sql.Database) {
currentDb := ctx.GetCurrentDatabase()
currBase, currRev := dsess.SplitRevisionDbName(currentDb)
p.mu.RLock()
showBranches, _ := dsess.GetBooleanSystemVar(ctx, dsess.ShowBranchDatabases)
all = make([]sql.Database, 0, len(p.databases))
for _, db := range p.databases {
base, _ := dsess.SplitRevisionDbName(db.Name())
// If there's a revision database in use, swap that one in for its base db, but keep the same name
if currRev != "" && strings.ToLower(currBase) == strings.ToLower(base) {
var err error
var ok bool
db, ok, err = p.databaseForRevision(ctx, currentDb, currBase)
if err != nil || !ok {
// TODO: this interface is wrong, needs to return errors
ctx.GetLogger().Warnf("error fetching revision databases: %s", err.Error())
}
}
all = append(all, db)
if showBranches {