-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Greatly improved forms with dbt profile browsing (#8)
This PR greatly improves the forms that compose the TUI, based on feedback from the dbt Labs DX team. - Now unified into one form with conditional visibility rather than multiple forms with conditional logic - This allows shift+tab and tab to back/forward through the entire thing - Validated input to prevent entering blank values - Default values where sensible so you can Just Hit Enter - We fetch all the dbt profiles before the form runs, so you can browse them rather than trying to enter the name correctly, this will error early if there are parsing issues with the profiles rather than after you fill out the form
- Loading branch information
Showing
14 changed files
with
351 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type DbtProfile struct { | ||
Target string `yaml:"target"` | ||
Outputs map[string]struct { | ||
ConnType string `yaml:"type"` | ||
Account string `yaml:"account"` | ||
User string `yaml:"user"` | ||
Role string `yaml:"role"` | ||
Authenticator string `yaml:"authenticator"` | ||
Database string `yaml:"database"` | ||
Schema string `yaml:"schema"` | ||
Project string `yaml:"project"` | ||
Dataset string `yaml:"dataset"` | ||
Path string `yaml:"path"` | ||
Threads int `yaml:"threads"` | ||
} `yaml:"outputs"` | ||
} | ||
|
||
type DbtProfiles map[string]DbtProfile | ||
|
||
func FetchDbtProfiles() (DbtProfiles, error) { | ||
paths := []string{ | ||
filepath.Join(".", "profiles.yml"), | ||
filepath.Join(os.Getenv("HOME"), ".dbt", "profiles.yml"), | ||
} | ||
ps := DbtProfiles{} | ||
for _, path := range paths { | ||
pf := DbtProfiles{} | ||
yf, err := os.ReadFile(path) | ||
if err != nil { | ||
continue | ||
} | ||
if err = yaml.Unmarshal(yf, pf); err != nil { | ||
log.Fatalf("Could not read dbt profile, \nlikely unsupported fields or formatting issues\n please open an issue: %v\n", err) | ||
} | ||
for k, v := range pf { | ||
ps[k] = v | ||
} | ||
} | ||
return ps, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestFetchDbtProfiles(t *testing.T) { | ||
CreateTempDbtProfiles(t) | ||
defer os.RemoveAll(os.Getenv("HOME")) | ||
defer os.Unsetenv("HOME") | ||
profiles, err := FetchDbtProfiles() | ||
if err != nil { | ||
t.Fatalf("Error fetching dbt profiles: %v\n", err) | ||
} | ||
if err != nil { | ||
t.Fatalf("Error fetching dbt profiles: %v\n", err) | ||
} | ||
if profiles["elf"].Outputs["dev"].ConnType != "snowflake" { | ||
t.Fatalf("Expected snowflake, got %s\n", profiles["elf"].Outputs["dev"].ConnType) | ||
} | ||
if profiles["human"].Outputs["dev"].ConnType != "bigquery" { | ||
t.Fatalf("Expected bigquery, got %s\n", profiles["human"].Outputs["dev"].ConnType) | ||
} | ||
if profiles["dwarf"].Outputs["dev"].ConnType != "duckdb" { | ||
t.Fatalf("Expected duckdb, got %s\n", profiles["dwarf"].Outputs["dev"].ConnType) | ||
} | ||
} |
Oops, something went wrong.