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.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filego.temporal.io/server/tools/common/schema/test/setuptest.go · 151 LOCtest/setuptest.gogo.temporal.io/server/tools/common/schema/test/updatetest.go · 161 LOCtest/updatetest.gogo.temporal.io/server/tools/sql/clitest/handler_tests.go · 57 LOCclitest/handler_tests.gogo.temporal.io/server/tools/sql/clitest/setup_task_tests.go · 116 LOCclitest/setup_task_tests…go.temporal.io/server/tools/sql/clitest/update_task_tests.go · 92 LOCclitest/update_task_test…go.temporal.io/server/tools/sql/conn.go · 110 LOCsql/conn.gogo.temporal.io/server/tools/sql/main.go · 222 LOCsql/main.goTestVisibilityDryrun · 0 introduced LOCTestVisibilityDryrunTestVisibilityDryrun · 0 introduced LOCTestVisibilityDryrunquery_util.go ×3 · 6 introduced LOCquery_util.go ×3TestUpdateSchema · 0 introduced LOCTestUpdateSchemaTestUpdateSchema · 0 introduced LOCTestUpdateSchemaTestUpdateSchema · 0 introduced LOCTestUpdateSchemaTestDryrun · 0 introduced LOCTestDryrunTestVisibilityDryrun · 0 introduced LOCTestVisibilityDryrunTestDryrun · 0 introduced LOCTestDryrunTestDryrun · 0 introduced LOCTestDryrunTestVerifyCompatibleVersion · 0 introduced LOCTestVerifyCompatibleVers…update_task_tests.go ×1 · 6 introduced LOCupdate_task_tests.go ×1TestVerifyCompatibleVersion · 0 introduced LOCTestVerifyCompatibleVers…db.go ×2 · 6 introduced LOCdb.go ×2update_task_tests.go ×1 · 8 introduced LOCupdate_task_tests.go ×1TestSetupSchema · 0 introduced LOCTestSetupSchemaupdate_task_tests.go ×1 · 8 introduced LOCupdate_task_tests.go ×1TestSetupSchema · 0 introduced LOCTestSetupSchemaupdate_task_tests.go ×4 · 37 introduced LOCupdate_task_tests.go ×4TestSetupSchema · 0 introduced LOCTestSetupSchemadb.go ×2 · 6 introduced LOCdb.go ×2setuptest.go ×1 · 11 introduced LOCsetuptest.go ×1version_tests.go ×4 · 78 introduced LOCversion_tests.go ×4dbtest.go ×4 · 8 introduced LOCdbtest.go ×4handler.go ×4 · 13 introduced LOChandler.go ×4pgx.go ×1 · 4 introduced LOCpgx.go ×1pq.go ×1 · 4 introduced LOCpq.go ×1TestCreateDatabase · 0 introduced LOCTestCreateDatabaseTestCreateDatabase · 0 introduced LOCTestCreateDatabaseTestCreateDatabaseIdempotent · 0 introduced LOCTestCreateDatabaseIdempo…admin.go ×1 · 6 introduced LOCadmin.go ×1TestCreateDatabase · 0 introduced LOCTestCreateDatabasesetup_task_tests.go ×1 · 16 introduced LOCsetup_task_tests.go ×1setup_task_tests.go ×1 · 29 introduced LOCsetup_task_tests.go ×1handler.go ×5 · 17 introduced LOChandler.go ×5setup_task_tests.go ×4 · 21 introduced LOCsetup_task_tests.go ×4main.go ×1 · 4 introduced LOCmain.go ×1handler.go ×4 · 141 introduced LOChandler.go ×4TestValidateConnectConfig, TestValidateConnectConfig · 0 introduced LOCTestValidateConnectConfi…handler_tests.go ×3 · 31 introduced LOChandler_tests.go ×3handler.go ×4 · 6 introduced LOChandler.go ×4TestValidateConnectConfig · introduced test · go.temporal.io/server/tools/tests/TestMySQLHandlerTestSuite/TestValidateConnectConfigTestValidateConnectConfi…TestCreateDatabase · introduced test · go.temporal.io/server/tools/tests/TestMySQLSetupSchemaTestSuite/TestCreateDatabaseTestCreateDatabaseTestCreateDatabaseIdempotent · introduced test · go.temporal.io/server/tools/tests/TestMySQLSetupSchemaTestSuite/TestCreateDatabaseIdempotentTestCreateDatabaseIdempo…TestSetupSchema · introduced test · go.temporal.io/server/tools/tests/TestMySQLSetupSchemaTestSuite/TestSetupSchemaTestSetupSchemaTestDryrun · introduced test · go.temporal.io/server/tools/tests/TestMySQLUpdateSchemaTestSuite/TestDryrunTestDryrunTestUpdateSchema · introduced test · go.temporal.io/server/tools/tests/TestMySQLUpdateSchemaTestSuite/TestUpdateSchemaTestUpdateSchemaTestVisibilityDryrun · introduced test · go.temporal.io/server/tools/tests/TestMySQLUpdateSchemaTestSuite/TestVisibilityDryrunTestVisibilityDryrunTestVerifyCompatibleVersion · introduced test · go.temporal.io/server/tools/tests/TestMySQLVersionTestSuite/TestVerifyCompatibleVersionTestVerifyCompatibleVers…TestValidateConnectConfig · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLHandlerTestSuite/TestValidateConnectConfigTestValidateConnectConfi…TestCreateDatabase · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLSetupSchemaTestSuite/TestCreateDatabaseTestCreateDatabaseTestCreateDatabaseIdempotent · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLSetupSchemaTestSuite/TestCreateDatabaseIdempotentTestCreateDatabaseIdempo…TestSetupSchema · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLSetupSchemaTestSuite/TestSetupSchemaTestSetupSchemaTestDryrun · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLUpdateSchemaTestSuite/TestDryrunTestDryrunTestUpdateSchema · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLUpdateSchemaTestSuite/TestUpdateSchemaTestUpdateSchemaTestVisibilityDryrun · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLUpdateSchemaTestSuite/TestVisibilityDryrunTestVisibilityDryrunTestVerifyCompatibleVersion · introduced test · go.temporal.io/server/tools/tests/TestPostgres/TestPostgreSQLVersionTestSuite/TestVerifyCompatibleVersionTestVerifyCompatibleVers…TestValidateConnectConfig · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLHandlerTestSuite/TestValidateConnectConfigTestValidateConnectConfi…TestCreateDatabase · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLSetupSchemaTestSuite/TestCreateDatabaseTestCreateDatabaseTestCreateDatabaseIdempotent · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLSetupSchemaTestSuite/TestCreateDatabaseIdempotentTestCreateDatabaseIdempo…TestSetupSchema · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLSetupSchemaTestSuite/TestSetupSchemaTestSetupSchemaTestDryrun · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLUpdateSchemaTestSuite/TestDryrunTestDryrunTestUpdateSchema · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLUpdateSchemaTestSuite/TestUpdateSchemaTestUpdateSchemaTestVisibilityDryrun · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLUpdateSchemaTestSuite/TestVisibilityDryrunTestVisibilityDryrunTestVerifyCompatibleVersion · introduced test · go.temporal.io/server/tools/tests/TestPostgresPGX/TestPostgreSQLVersionTestSuite/TestVerifyCompatibleVersionTestVerifyCompatibleVers…Focused file · go.temporal.io/server/tools/sql/handler.go · 182 LOCsql/handler.go

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.

1 package sql
2
3 import (
4 "fmt"
5 "net"
6 "net/url"
7
8 "github.com/urfave/cli"
9 "go.temporal.io/server/common/auth"
10 "go.temporal.io/server/common/config"
11 "go.temporal.io/server/common/log"
12 "go.temporal.io/server/common/log/tag"
13 "go.temporal.io/server/tools/common/schema"
14 )
15
16 // setupSchema executes the setupSchemaTask
17 // using the given command line arguments
18 // as input
19 > func setupSchema(cli *cli.Context, logger log.Logger) error { handler.go ×4
20 > cfg, err := parseConnectConfig(cli)
21 > if err != nil {
22 logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
23 return err
24 }
25 > conn, err := NewConnection(cfg, logger) handler.go ×4
26 > if err != nil {
27 logger.Error("Unable to connect to SQL database.", tag.Error(err))
28 return err
29 }
30 > defer conn.Close() handler.go ×4
31 > if err := schema.Setup(cli, conn, logger); err != nil {
32 > logger.Error("Unable to setup SQL schema.", tag.Error(err)) setuptest.go ×1
33 > return err
34 > }
35 > return nil handler.go ×4
36 }
37
38 // updateSchema executes the updateSchemaTask
39 // using the given command line args as input
40 > func updateSchema(cli *cli.Context, logger log.Logger) error { update_task_tests.go ×4
41 > cfg, err := parseConnectConfig(cli)
42 > if err != nil {
43 logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
44 return err
45 }
46 > conn, err := NewConnection(cfg, logger) update_task_tests.go ×4
47 > if err != nil {
48 logger.Error("Unable to connect to SQL database.", tag.Error(err))
49 return err
50 }
51 > defer conn.Close() update_task_tests.go ×4
52 > if err := schema.Update(cli, conn, logger); err != nil {
53 logger.Error("Unable to update SQL schema.", tag.Error(err))
54 return err
55 }
56 > return nil update_task_tests.go ×4
57 }
58
59 // createDatabase creates a sql database
60 > func createDatabase(cli *cli.Context, logger log.Logger) error { handler.go ×5
61 > cfg, err := parseConnectConfig(cli)
62 > if err != nil {
63 logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
64 return err
65 }
66 > defaultDb := cli.String(schema.CLIOptDefaultDb) handler.go ×5
67 > err = DoCreateDatabase(cfg, defaultDb, logger)
68 > if err != nil {
69 logger.Error("Unable to create SQL database.", tag.Error(err))
70 return err
71 }
72 > return nil handler.go ×5
73 }
74
75 > func DoCreateDatabase(cfg *config.SQL, defaultDb string, logger log.Logger) error { handler.go ×5
76 > dbToCreate := cfg.DatabaseName
77 > cfg.DatabaseName = defaultDb
78 > conn, err := NewConnection(cfg, logger)
79 > if err != nil {
80 return err
81 }
82 > defer conn.Close() handler.go ×5
83 > return conn.CreateDatabase(dbToCreate)
84 }
85
86 // dropDatabase drops a sql database
87 func dropDatabase(cli *cli.Context, logger log.Logger) error {
88 cfg, err := parseConnectConfig(cli)
89 if err != nil {
90 logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
91 return err
92 }
93 defaultDb := cli.String(schema.CLIOptDefaultDb)
94 err = DoDropDatabase(cfg, defaultDb, logger)
95 if err != nil {
96 logger.Error("Unable to drop SQL database.", tag.Error(err))
97 return err
98 }
99 return nil
100 }
101
102 func DoDropDatabase(cfg *config.SQL, defaultDb string, logger log.Logger) error {
103 dbToDrop := cfg.DatabaseName
104 cfg.DatabaseName = defaultDb
105 conn, err := NewConnection(cfg, logger)
106 if err != nil {
107 return err
108 }
109 err = conn.DropDatabase(dbToDrop)
110 if err != nil {
111 return err
112 }
113 conn.Close()
114 return nil
115 }
116
117 > func parseConnectConfig(cli *cli.Context) (*config.SQL, error) { handler.go ×4
118 > cfg := new(config.SQL)
119 >
120 > host := cli.GlobalString(schema.CLIOptEndpoint)
121 > port := cli.GlobalInt(schema.CLIOptPort)
122 > cfg.ConnectAddr = fmt.Sprintf("%s:%v", host, port)
123 > cfg.User = cli.GlobalString(schema.CLIOptUser)
124 > cfg.Password = cli.GlobalString(schema.CLIOptPassword)
125 > cfg.DatabaseName = cli.GlobalString(schema.CLIOptDatabase)
126 > cfg.PluginName = cli.GlobalString(schema.CLIOptPluginName)
127 >
128 > if cfg.ConnectAttributes == nil {
129 > cfg.ConnectAttributes = map[string]string{}
130 > }
131 > connectAttributesQueryString := cli.GlobalString(schema.CLIOptConnectAttributes)
132 > if connectAttributesQueryString != "" {
133 values, err := url.ParseQuery(connectAttributesQueryString)
134 if err != nil {
135 return nil, fmt.Errorf("invalid connect attributes: %v", err)
136 }
137 for key, vals := range values {
138 // check to ensure only one value is provider per key
139 if len(vals) > 1 {
140 return nil, fmt.Errorf("invalid connect attribute %v, only 1 value allowed: %v", key, vals)
141 }
142 cfg.ConnectAttributes[key] = vals[0]
143 }
144 }
145
146 > if cli.GlobalBool(schema.CLIFlagEnableTLS) { handler.go ×4
147 cfg.TLS = &auth.TLS{
148 Enabled: true,
149 CertFile: cli.GlobalString(schema.CLIFlagTLSCertFile),
150 KeyFile: cli.GlobalString(schema.CLIFlagTLSKeyFile),
151 CaFile: cli.GlobalString(schema.CLIFlagTLSCaFile),
152 ServerName: cli.GlobalString(schema.CLIFlagTLSHostName),
153 EnableHostVerification: !cli.GlobalBool(schema.CLIFlagTLSDisableHostVerification),
154 }
155 }
156
157 > if err := ValidateConnectConfig(cfg); err != nil { handler.go ×4
158 return nil, err
159 }
160
161 > return cfg, nil handler.go ×4
162 }
163
164 // ValidateConnectConfig validates params
165 > func ValidateConnectConfig(cfg *config.SQL) error { handler.go ×4
166 > host, _, err := net.SplitHostPort(cfg.ConnectAddr)
167 > if err != nil {
168 > return schema.NewConfigError("invalid host and port " + cfg.ConnectAddr) handler_tests.go ×3
169 > }
170 > if len(host) == 0 { handler.go ×4
171 return schema.NewConfigError("missing sql endpoint argument " + flag(schema.CLIOptEndpoint))
172 }
173 > if cfg.DatabaseName == "" { handler.go ×4
174 > return schema.NewConfigError("missing " + flag(schema.CLIOptDatabase) + " argument") handler_tests.go ×3
175 > }
176
177 > return nil handler.go ×4
178 }
179
180 > func flag(opt string) string { handler_tests.go ×3
181 > return "(-" + opt + ")"
182 > }