mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-20 02:24:58 -05:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user