-
Notifications
You must be signed in to change notification settings - Fork 814
/
types.go
182 lines (172 loc) · 7.22 KB
/
types.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package schema
import (
"fmt"
"regexp"
)
type (
// ConfigError is an error type that
// represents a problem with the config
ConfigError struct {
msg string
}
// UpdateConfig holds the config
// params for executing a UpdateTask
UpdateConfig struct {
DBName string
TargetVersion string
SchemaDir string
IsDryRun bool
}
// SetupConfig holds the config
// params need by the SetupTask
SetupConfig struct {
SchemaFilePath string
InitialVersion string
Overwrite bool // overwrite previous data
DisableVersioning bool // do not use schema versioning
}
// DB is the database interface that's required to be implemented
// for the schema-tool to work
DB interface {
// Exec executes a cql statement
Exec(stmt string, args ...interface{}) error
// DropAllTables drops all tables
DropAllTables() error
// CreateSchemaVersionTables sets up the schema version tables
CreateSchemaVersionTables() error
// ReadSchemaVersion returns the current schema version for the keyspace
ReadSchemaVersion() (string, error)
// UpdateSchemaVersion updates the schema version for the keyspace
UpdateSchemaVersion(newVersion string, minCompatibleVersion string) error
// WriteSchemaUpdateLog adds an entry to the schema update history table
WriteSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, desc string) error
// Close gracefully closes the client object
Close()
}
)
const (
// CLIOptEndpoint is the cli option for endpoint
CLIOptEndpoint = "endpoint"
// CLIOptPort is the cli option for port
CLIOptPort = "port"
// CLIOptUser is the cli option for user
CLIOptUser = "user"
// CLIOptPassword is the cli option for password
CLIOptPassword = "password"
// CLIOptTimeout is the cli option for timeout
CLIOptTimeout = "timeout"
// CLIOptKeyspace is the cli option for keyspace
CLIOptKeyspace = "keyspace"
// CLIOptDatabase is the cli option for database
CLIOptDatabase = "database"
// CLIOptPluginName is the cli option for plugin name
CLIOptPluginName = "plugin"
// CLIOptConnectAttributes is the cli option for connect attributes (key/values via a url query string)
CLIOptConnectAttributes = "connect-attributes"
// CLIOptVersion is the cli option for version
CLIOptVersion = "version"
// CLIOptSchemaFile is the cli option for schema file
CLIOptSchemaFile = "schema-file"
// CLIOptOverwrite is the cli option for overwrite
CLIOptOverwrite = "overwrite"
// CLIOptDisableVersioning is the cli option to disabling versioning
CLIOptDisableVersioning = "disable-versioning"
// CLIOptTargetVersion is the cli option for target version
CLIOptTargetVersion = "version"
// CLIOptDryrun is the cli option for enabling dryrun
CLIOptDryrun = "dryrun"
// CLIOptSchemaDir is the cli option for schema directory
CLIOptSchemaDir = "schema-dir"
// CLIOptReplicationFactor is the cli option for replication factor
CLIOptReplicationFactor = "replication-factor"
// CLIOptDatacenter is the cli option for NetworkTopologyStrategy datacenter
CLIOptDatacenter = "datacenter"
// CLIOptQuiet is the cli option for quiet mode
CLIOptQuiet = "quiet"
// CLIOptForce is the cli option for force mode
CLIOptForce = "force"
// CLIFlagEndpoint is the cli flag for endpoint
CLIFlagEndpoint = CLIOptEndpoint + ", ep"
// CLIFlagPort is the cli flag for port
CLIFlagPort = CLIOptPort + ", p"
// CLIFlagUser is the cli flag for user
CLIFlagUser = CLIOptUser + ", u"
// CLIFlagPassword is the cli flag for password
CLIFlagPassword = CLIOptPassword + ", pw"
// CLIFlagTimeout is the cli flag for timeout
CLIFlagTimeout = CLIOptTimeout + ", t"
// CLIFlagKeyspace is the cli flag for keyspace
CLIFlagKeyspace = CLIOptKeyspace + ", k"
// CLIFlagDatabase is the cli flag for database
CLIFlagDatabase = CLIOptDatabase + ", db"
// CLIFlagPluginName is the cli flag for plugin name
CLIFlagPluginName = CLIOptPluginName + ", pl"
// CLIFlagConnectAttributes allows arbitrary connect attributes
CLIFlagConnectAttributes = CLIOptConnectAttributes + ", ca"
// CLIFlagVersion is the cli flag for version
CLIFlagVersion = CLIOptVersion + ", v"
// CLIFlagSchemaFile is the cli flag for schema file
CLIFlagSchemaFile = CLIOptSchemaFile + ", f"
// CLIFlagOverwrite is the cli flag for overwrite
CLIFlagOverwrite = CLIOptOverwrite + ", o"
// CLIFlagDisableVersioning is the cli flag for disabling versioning
CLIFlagDisableVersioning = CLIOptDisableVersioning + ", d"
// CLIFlagTargetVersion is the cli flag for target version
CLIFlagTargetVersion = CLIOptTargetVersion + ", v"
// CLIFlagDryrun is the cli flag for dryrun
CLIFlagDryrun = CLIOptDryrun + ", y"
// CLIFlagSchemaDir is the cli flag for schema directory
CLIFlagSchemaDir = CLIOptSchemaDir + ", d"
// CLIFlagReplicationFactor is the cli flag for replication factor
CLIFlagReplicationFactor = CLIOptReplicationFactor + ", rf"
// CLIFlagDatacenter is the cli option for NetworkTopologyStrategy datacenter
CLIFlagDatacenter = CLIOptDatacenter + ", dc"
// CLIFlagQuiet is the cli flag for quiet mode
CLIFlagQuiet = CLIOptQuiet + ", q"
// CLIFlagForce is the cli flag for force mode
CLIFlagForce = CLIOptForce + ", f"
// CLIFlagEnableTLS enables cassandra client TLS
CLIFlagEnableTLS = "tls"
// CLIFlagTLSCertFile is the optional tls cert file (tls must be enabled)
CLIFlagTLSCertFile = "tls-cert-file"
// CLIFlagTLSKeyFile is the optional tls key file (tls must be enabled)
CLIFlagTLSKeyFile = "tls-key-file"
// CLIFlagTLSCaFile is the optional tls CA file (tls must be enabled)
CLIFlagTLSCaFile = "tls-ca-file"
// CLIFlagTLSEnableHostVerification enables tls host verification (tls must be enabled)
CLIFlagTLSEnableHostVerification = "tls-enable-host-verification"
)
// DryrunDBName is the db name used for dryrun
const DryrunDBName = "_temporal_dryrun_"
var rmspaceRegex = regexp.MustCompile(`\s+`)
// NewConfigError creates and returns an instance of ConfigError
func NewConfigError(msg string) error {
return &ConfigError{msg: msg}
}
// Error returns a string representation of this error
func (e *ConfigError) Error() string {
return fmt.Sprintf("Config Error:%v", e.msg)
}