Skip to content

Commit b31a392

Browse files
committed
List postgres databases during Lakebase plugin selection
1 parent 158ca39 commit b31a392

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

libs/apps/prompt/listers.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@ func ListPostgresBranches(ctx context.Context, projectName string) ([]ListItem,
397397
return out, nil
398398
}
399399

400+
// ListPostgresDatabases returns databases within a Lakebase Autoscaling branch as selectable items.
401+
func ListPostgresDatabases(ctx context.Context, branchName string) ([]ListItem, error) {
402+
w, err := workspaceClient(ctx)
403+
if err != nil {
404+
return nil, err
405+
}
406+
iter := w.Postgres.ListDatabases(ctx, postgres.ListDatabasesRequest{Parent: branchName})
407+
databases, err := listing.ToSlice(ctx, iter)
408+
if err != nil {
409+
return nil, err
410+
}
411+
out := make([]ListItem, 0, len(databases))
412+
for _, db := range databases {
413+
label := extractIDFromName(db.Name, "databases")
414+
if db.Status != nil && db.Status.PostgresDatabase != "" {
415+
label = db.Status.PostgresDatabase
416+
}
417+
out = append(out, ListItem{ID: db.Name, Label: label})
418+
}
419+
return out, nil
420+
}
421+
400422
// ListGenieSpaces returns Genie spaces as selectable items.
401423
func ListGenieSpaces(ctx context.Context) ([]ListItem, error) {
402424
w, err := workspaceClient(ctx)

libs/apps/prompt/prompt.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,22 +562,23 @@ func PromptForPostgres(ctx context.Context, r manifest.Resource, required bool)
562562
return nil, nil
563563
}
564564

565-
// Step 3: enter a database name (pre-filled with default)
566-
dbName := "databricks_postgres"
567-
theme := AppkitTheme()
568-
err = huh.NewInput().
569-
Title("Database name").
570-
Description("Enter the database name to connect to").
571-
Value(&dbName).
572-
WithTheme(theme).
573-
Run()
565+
// Step 3: pick a database within the branch
566+
var databases []ListItem
567+
err = RunWithSpinnerCtx(ctx, "Fetching databases...", func() error {
568+
var fetchErr error
569+
databases, fetchErr = ListPostgresDatabases(ctx, branchName)
570+
return fetchErr
571+
})
572+
if err != nil {
573+
return nil, err
574+
}
575+
dbName, err := PromptFromList(ctx, "Select Database", "no databases found in branch "+branchName, databases, required)
574576
if err != nil {
575577
return nil, err
576578
}
577579
if dbName == "" {
578580
return nil, nil
579581
}
580-
printAnswered(ctx, "Database", dbName)
581582

582583
return map[string]string{
583584
r.Key() + ".branch": branchName,

0 commit comments

Comments
 (0)