go.temporal.io/server/tools/sql/handler.go
182 LOC · 65 covered · 117 uncovered · 25 ranges · 41 concepts · 7 introducers · 24 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package sql
import (
"fmt"
"net"
"net/url"
"github.com/urfave/cli"
"go.temporal.io/server/common/auth"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/tools/common/schema"
)
// setupSchema executes the setupSchemaTask
// using the given command line arguments
// as input
cfg, err := parseConnectConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if err != nil {
logger.Error("Unable to connect to SQL database.", tag.Error(err))
return err
}
if err := schema.Setup(cli, conn, logger); err != nil {
return err
}
}
// updateSchema executes the updateSchemaTask
// using the given command line args as input
cfg, err := parseConnectConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if err != nil {
logger.Error("Unable to connect to SQL database.", tag.Error(err))
return err
}
if err := schema.Update(cli, conn, logger); err != nil {
logger.Error("Unable to update SQL schema.", tag.Error(err))
return err
}
}
// createDatabase creates a sql database
cfg, err := parseConnectConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
err = DoCreateDatabase(cfg, defaultDb, logger)
if err != nil {
logger.Error("Unable to create SQL database.", tag.Error(err))
return err
}
}
func DoCreateDatabase(cfg *config.SQL, defaultDb string, logger log.Logger) error {
handler.go ×5
dbToCreate := cfg.DatabaseName
cfg.DatabaseName = defaultDb
conn, err := NewConnection(cfg, logger)
if err != nil {
return err
}
return conn.CreateDatabase(dbToCreate)
}
// dropDatabase drops a sql database
func dropDatabase(cli *cli.Context, logger log.Logger) error {
cfg, err := parseConnectConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
defaultDb := cli.String(schema.CLIOptDefaultDb)
err = DoDropDatabase(cfg, defaultDb, logger)
if err != nil {
logger.Error("Unable to drop SQL database.", tag.Error(err))
return err
}
return nil
}
func DoDropDatabase(cfg *config.SQL, defaultDb string, logger log.Logger) error {
dbToDrop := cfg.DatabaseName
cfg.DatabaseName = defaultDb
conn, err := NewConnection(cfg, logger)
if err != nil {
return err
}
err = conn.DropDatabase(dbToDrop)
if err != nil {
return err
}
conn.Close()
return nil
}
cfg := new(config.SQL)
host := cli.GlobalString(schema.CLIOptEndpoint)
port := cli.GlobalInt(schema.CLIOptPort)
cfg.ConnectAddr = fmt.Sprintf("%s:%v", host, port)
cfg.User = cli.GlobalString(schema.CLIOptUser)
cfg.Password = cli.GlobalString(schema.CLIOptPassword)
cfg.DatabaseName = cli.GlobalString(schema.CLIOptDatabase)
cfg.PluginName = cli.GlobalString(schema.CLIOptPluginName)
if cfg.ConnectAttributes == nil {
cfg.ConnectAttributes = map[string]string{}
}
connectAttributesQueryString := cli.GlobalString(schema.CLIOptConnectAttributes)
if connectAttributesQueryString != "" {
values, err := url.ParseQuery(connectAttributesQueryString)
if err != nil {
return nil, fmt.Errorf("invalid connect attributes: %v", err)
}
for key, vals := range values {
// check to ensure only one value is provider per key
if len(vals) > 1 {
return nil, fmt.Errorf("invalid connect attribute %v, only 1 value allowed: %v", key, vals)
}
cfg.ConnectAttributes[key] = vals[0]
}
}
cfg.TLS = &auth.TLS{
Enabled: true,
CertFile: cli.GlobalString(schema.CLIFlagTLSCertFile),
KeyFile: cli.GlobalString(schema.CLIFlagTLSKeyFile),
CaFile: cli.GlobalString(schema.CLIFlagTLSCaFile),
ServerName: cli.GlobalString(schema.CLIFlagTLSHostName),
EnableHostVerification: !cli.GlobalBool(schema.CLIFlagTLSDisableHostVerification),
}
}
return nil, err
}
}
// ValidateConnectConfig validates params
host, _, err := net.SplitHostPort(cfg.ConnectAddr)
if err != nil {
}
return schema.NewConfigError("missing sql endpoint argument " + flag(schema.CLIOptEndpoint))
}
return schema.NewConfigError("missing " + flag(schema.CLIOptDatabase) + " argument")
handler_tests.go ×3
}
}
return "(-" + opt + ")"
}