go.temporal.io/server/tools/sql/main.go

222 LOC · 134 covered · 88 uncovered · 7 ranges · 38 concepts · 5 introducers · 21 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/updatetest.go · 161 LOCtest/updatetest.gogo.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/handler.go · 182 LOCsql/handler.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 ×4TestCreateDatabase · 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…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…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/main.go · 222 LOCsql/main.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 "os"
6
7 "github.com/urfave/cli"
8 "go.temporal.io/server/common/headers"
9 "go.temporal.io/server/common/log"
10 "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql"
11 dbschemas "go.temporal.io/server/schema"
12 "go.temporal.io/server/temporal/environment"
13 "go.temporal.io/server/tools/common/schema"
14 )
15
16 // RunTool runs the temporal-sql-tool command line tool
17 > func RunTool(args []string) error { main.go ×1
18 > app := BuildCLIOptions()
19 > return app.Run(args)
20 > }
21
22 // root handler for all cli commands
23 > func cliHandler(c *cli.Context, handler func(c *cli.Context, logger log.Logger) error, logger log.Logger) { handler.go ×4
24 > quiet := c.GlobalBool(schema.CLIOptQuiet)
25 > err := handler(c, logger)
26 > if err != nil && !quiet {
27 os.Exit(1)
28 }
29 }
30
31 // BuildCLIOptions builds the options for cli
32 > func BuildCLIOptions() *cli.App { handler.go ×4
33 >
34 > app := cli.NewApp()
35 > app.Name = "temporal-sql-tool"
36 > app.Usage = "Command line tool for temporal sql operations"
37 > app.Version = headers.ServerVersion
38 >
39 > logger := log.NewCLILogger()
40 >
41 > app.Flags = []cli.Flag{
42 > cli.StringFlag{
43 > Name: schema.CLIFlagEndpoint,
44 > Value: environment.GetMySQLAddress(),
45 > Usage: "hostname or ip address of sql host to connect to",
46 > EnvVar: "SQL_HOST",
47 > },
48 > cli.IntFlag{
49 > Name: schema.CLIFlagPort,
50 > Value: environment.GetMySQLPort(),
51 > Usage: "port of sql host to connect to",
52 > EnvVar: "SQL_PORT",
53 > },
54 > cli.StringFlag{
55 > Name: schema.CLIFlagUser,
56 > Value: "",
57 > Usage: "user name used for authentication when connecting to sql host",
58 > EnvVar: "SQL_USER",
59 > },
60 > cli.StringFlag{
61 > Name: schema.CLIFlagPassword,
62 > Value: "",
63 > Usage: "password used for authentication when connecting to sql host",
64 > EnvVar: "SQL_PASSWORD",
65 > },
66 > cli.StringFlag{
67 > Name: schema.CLIFlagDatabase,
68 > Value: "temporal",
69 > Usage: "name of the sql database",
70 > EnvVar: "SQL_DATABASE",
71 > },
72 > cli.StringFlag{
73 > Name: schema.CLIFlagPluginName,
74 > Value: mysql.PluginName,
75 > Usage: "name of the sql plugin",
76 > EnvVar: "SQL_PLUGIN",
77 > },
78 > cli.BoolFlag{
79 > Name: schema.CLIFlagQuiet,
80 > Usage: "Don't set exit status to 1 on error",
81 > },
82 > cli.StringFlag{
83 > Name: schema.CLIFlagConnectAttributes,
84 > Usage: "sql connect attributes",
85 > EnvVar: "SQL_CONNECT_ATTRIBUTES",
86 > },
87 > cli.BoolFlag{
88 > Name: schema.CLIFlagEnableTLS,
89 > Usage: "enable TLS over sql connection",
90 > EnvVar: "SQL_TLS",
91 > },
92 > cli.StringFlag{
93 > Name: schema.CLIFlagTLSCertFile,
94 > Usage: "sql tls client cert path (tls must be enabled)",
95 > EnvVar: "SQL_TLS_CERT_FILE",
96 > },
97 > cli.StringFlag{
98 > Name: schema.CLIFlagTLSKeyFile,
99 > Usage: "sql tls client key path (tls must be enabled)",
100 > EnvVar: "SQL_TLS_KEY_FILE",
101 > },
102 > cli.StringFlag{
103 > Name: schema.CLIFlagTLSCaFile,
104 > Usage: "sql tls client ca file (tls must be enabled)",
105 > EnvVar: "SQL_TLS_CA_FILE",
106 > },
107 > cli.StringFlag{
108 > Name: schema.CLIFlagTLSHostName,
109 > Value: "",
110 > Usage: "override for target server name",
111 > EnvVar: "SQL_TLS_SERVER_NAME",
112 > },
113 > cli.BoolFlag{
114 > Name: schema.CLIFlagTLSDisableHostVerification,
115 > Usage: "disable tls host name verification (tls must be enabled)",
116 > EnvVar: "SQL_TLS_DISABLE_HOST_VERIFICATION",
117 > },
118 > }
119 >
120 > app.Commands = []cli.Command{
121 > {
122 > Name: "setup-schema",
123 > Aliases: []string{"setup"},
124 > Usage: "setup initial version of sql schema",
125 > Flags: []cli.Flag{
126 > cli.StringFlag{
127 > Name: schema.CLIFlagVersion,
128 > Usage: "initial version of the schema, cannot be used with disable-versioning",
129 > },
130 > cli.StringFlag{
131 > Name: schema.CLIFlagSchemaFile,
132 > Usage: "path to the .sql schema file; if un-specified, will just setup versioning tables",
133 > },
134 > cli.StringFlag{
135 > Name: schema.CLIFlagSchemaName,
136 > Usage: fmt.Sprintf("name of embedded schema directory with .sql file, one of: %v",
137 > dbschemas.PathsByDB("sql")),
138 > },
139 > cli.BoolFlag{
140 > Name: schema.CLIFlagDisableVersioning,
141 > Usage: "disable setup of schema versioning",
142 > },
143 > cli.BoolFlag{
144 > Name: schema.CLIFlagOverwrite,
145 > Usage: "drop all existing tables before setting up new schema",
146 > },
147 > },
148 > Action: func(c *cli.Context) {
149 > cliHandler(c, setupSchema, logger) handler.go ×4
150 > },
151 },
152 {
153 Name: "update-schema",
154 Aliases: []string{"update"},
155 Usage: "update sql schema to a specific version",
156 Flags: []cli.Flag{
157 cli.StringFlag{
158 Name: schema.CLIFlagTargetVersion,
159 Usage: "target version for the schema update, defaults to latest",
160 },
161 cli.StringFlag{
162 Name: schema.CLIFlagSchemaDir,
163 Usage: "path to directory containing versioned schema",
164 },
165 cli.StringFlag{
166 Name: schema.CLIFlagSchemaName,
167 Usage: fmt.Sprintf("name of embedded versioned schema, one of: %v",
168 dbschemas.PathsByDB("mysql")),
169 },
170 },
171 > Action: func(c *cli.Context) { update_task_tests.go ×4
172 > cliHandler(c, updateSchema, logger)
173 > },
174 },
175 {
176 Name: "create-database",
177 Aliases: []string{"create"},
178 Usage: "creates a database",
179 Flags: []cli.Flag{
180 cli.StringFlag{
181 Name: schema.CLIOptDefaultDb,
182 Usage: "optional default db to connect to, this is not the db to be created",
183 },
184 },
185 > Action: func(c *cli.Context) { handler.go ×5
186 > cliHandler(c, createDatabase, logger)
187 > },
188 },
189 {
190 Name: "drop-database",
191 Aliases: []string{"drop"},
192 Usage: "drops a database",
193 Flags: []cli.Flag{
194 cli.StringFlag{
195 Name: schema.CLIOptDefaultDb,
196 Usage: "optional default db to connect to, not the db to be deleted",
197 },
198 cli.BoolFlag{
199 Name: schema.CLIFlagForce,
200 Usage: "don't prompt for confirmation",
201 },
202 },
203 Action: func(c *cli.Context) {
204 drop := c.Bool(schema.CLIOptForce)
205 if !drop {
206 database := c.GlobalString(schema.CLIOptDatabase)
207 fmt.Printf("Are you sure you want to drop database %q (y/N)? ", database)
208 y := ""
209 _, _ = fmt.Scanln(&y)
210 if y == "y" || y == "Y" {
211 drop = true
212 }
213 }
214 if drop {
215 cliHandler(c, dropDatabase, logger)
216 }
217 },
218 },
219 }
220
221 > return app handler.go ×4
222 }