-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.go
37 lines (28 loc) · 1010 Bytes
/
schemas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package schemas
import (
"fmt"
"github.com/macinnir/dvc/core/lib"
"go.uber.org/zap"
)
const CommandName = "schemas"
// Import fetches the sql schema from the target database (specified in dvc.toml)
// and from that generates the json representation at `[schema name].schema.json`
func Cmd(log *zap.Logger, config *lib.Config, args []string) error {
schemaOrdered := []string{}
schemaMap := map[string][]string{}
for k := range config.Databases {
schemaName := lib.ExtractRootNameFromKey(config.Databases[k].Key)
if _, ok := schemaMap[schemaName]; !ok {
schemaMap[schemaName] = []string{}
schemaOrdered = append(schemaOrdered, schemaName)
}
schemaMap[schemaName] = append(schemaMap[schemaName], config.Databases[k].Key+" -> "+config.Databases[k].Host+"/"+config.Databases[k].Name)
}
for k := range schemaOrdered {
fmt.Println(" + " + schemaOrdered[k])
for l := range schemaMap[schemaOrdered[k]] {
fmt.Println(" - ", schemaMap[schemaOrdered[k]][l])
}
}
return nil
}