forked from bytebase/bytebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan.go
More file actions
203 lines (181 loc) · 6.65 KB
/
Copy pathplan.go
File metadata and controls
203 lines (181 loc) · 6.65 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package api
import "fmt"
// PlanType is the type for a plan.
type PlanType int
const (
// FREE is the plan type for FREE.
FREE PlanType = iota
// TEAM is the plan type for TEAM.
TEAM
// ENTERPRISE is the plan type for ENTERPRISE.
ENTERPRISE
)
// String returns the string format of plan type.
func (p PlanType) String() string {
switch p {
case FREE:
return "FREE"
case TEAM:
return "TEAM"
case ENTERPRISE:
return "ENTERPRISE"
}
return ""
}
// FeatureType is the type of a feature.
type FeatureType string
const (
// Change Workflow
// FeatureBackwardCompatibility checks if a DDL change is backward compatible.
// See https://bytebase.com/docs/features/sql-advisor/backward-compatibility-migration-check
//
// Currently, we only support MySQL/TiDB thanks to github.com/pingcap/parser
FeatureBackwardCompatibility FeatureType = "bb.feature.backward-compatibility"
// FeatureSchemaDrift detects if there occurs schema drift.
// See https://bytebase.com/docs/features/drift-detection
FeatureSchemaDrift FeatureType = "bb.feature.schema-drift"
// FeatureTaskScheduleTime allows user to run task at a scheduled time
FeatureTaskScheduleTime FeatureType = "bb.feature.task-schedule-time"
// FeatureMultiTenancy allows user to enable tenant mode for the project.
//
// Tenant mode allows user to track a group of homogeneous database changes together.
// e.g. A game studio may deploy many servers, each server is fully isolated with its
// own database. When a new game version is released, it may require to upgrade the
// underlying database schema, then tenant mode will help the studio to track the
// schema change across all databases.
FeatureMultiTenancy FeatureType = "bb.feature.multi-tenancy"
// FeatureDBAWorkflow enforces the DBA workflow.
//
// - Developers can't create and view instances since they are exclusively by DBA, they can
// only access database.
// - Developers can submit troubleshooting issue.
FeatureDBAWorkflow FeatureType = "bb.feature.dba-workflow"
// FeatureDataSource exposes the data source concept.
//
// Currently, we DO NOT expose this feature.
//
// Internally Bytebase stores instance username/password in a separate data source model.
// This allows a single instance to have multiple data sources (e.g. one RW and one RO).
// And from the user's perspective, the username/password
// look like the property of the instance, which are not. They are the property of data source which
// in turns belongs to the instance.
// - Support defining extra data source for a database and exposing the related data source UI.
FeatureDataSource FeatureType = "bb.feature.data-source"
// Policy Control
// FeatureApprovalPolicy allows user to specify approval policy for the environment
//
// e.g. One can configure to NOT require approval for dev environment while require
// manual approval for production.
FeatureApprovalPolicy FeatureType = "bb.feature.approval-policy"
// FeatureBackupPolicy allows user to specify backup policy for the environment
//
// e.g. One can configure to NOT require backup for dev environment while require
// weekly backup for staging and daily backup for production.
FeatureBackupPolicy FeatureType = "bb.feature.backup-policy"
// Admin & Security
// FeatureRBAC enables RBAC.
//
// - Workspace level RBAC
// - Project level RBAC
FeatureRBAC FeatureType = "bb.feature.rbac"
// Feature3rdPartyAuth allows user to authenticate (login) and authorize (sync project member)
//
// Currently, we only support GitLab EE/CE auth.
Feature3rdPartyAuth FeatureType = "bb.feature.3rd-party-auth"
// Branding
// FeatureBranding enables customized branding.
//
// Currently, we only support customizing the logo.
FeatureBranding FeatureType = "bb.feature.branding"
)
func (e FeatureType) String() string {
switch e {
case FeatureBackwardCompatibility:
return "bb.feature.backward-compatibility"
case FeatureSchemaDrift:
return "bb.feature.schema-drift"
case FeatureTaskScheduleTime:
return "bb.feature.task-schedule-time"
case FeatureMultiTenancy:
return "bb.feature.multi-tenancy"
case FeatureDBAWorkflow:
return "bb.feature.dba-workflow"
case FeatureDataSource:
return "bb.feature.data-source"
case FeatureApprovalPolicy:
return "bb.feature.approval-policy"
case FeatureBackupPolicy:
return "bb.feature.backup-policy"
case FeatureRBAC:
return "bb.feature.rbac"
case Feature3rdPartyAuth:
return "bb.feature.3rd-party-auth"
case FeatureBranding:
return "bb.feature.branding"
}
return ""
}
// Name returns a readable name of the feature
func (e FeatureType) Name() string {
switch e {
case FeatureBackwardCompatibility:
return "Backward compatibility"
case FeatureSchemaDrift:
return "Schema drift"
case FeatureTaskScheduleTime:
return "Task schedule time"
case FeatureMultiTenancy:
return "Multi-tenancy"
case FeatureDBAWorkflow:
return "DBA workflow"
case FeatureDataSource:
return "Data source"
case FeatureApprovalPolicy:
return "Approval policy"
case FeatureBackupPolicy:
return "Backup policy"
case FeatureRBAC:
return "RBAC"
case Feature3rdPartyAuth:
return "3rd party auth"
case FeatureBranding:
return "Branding"
}
return ""
}
// AccessErrorMessage returns a error message with feature name and minimum supported plan.
func (e FeatureType) AccessErrorMessage() string {
plan := e.minimumSupportedPlan()
return fmt.Sprintf("%s is a %s feature, please upgrade to access it.", e.Name(), plan.String())
}
// minimumSupportedPlan will find the minimum plan which support the target feature.
func (e FeatureType) minimumSupportedPlan() PlanType {
for i, enabled := range FeatureMatrix[e] {
if enabled {
return PlanType(i)
}
}
return ENTERPRISE
}
// FeatureMatrix is a map from the a particular feature to the respective enablement of a particular plan
var FeatureMatrix = map[FeatureType][3]bool{
"bb.feature.backward-compatibility": {false, true, true},
"bb.feature.schema-drift": {false, true, true},
"bb.feature.task-schedule-time": {false, true, true},
"bb.feature.multi-tenancy": {false, true, true},
"bb.feature.dba-workflow": {false, false, true},
"bb.feature.data-source": {false, false, false},
"bb.feature.approval-policy": {false, true, true},
"bb.feature.backup-policy": {false, true, true},
"bb.feature.rbac": {false, true, true},
"bb.feature.3rd-party-auth": {false, true, true},
"bb.feature.branding": {false, true, true},
}
// Plan is the API message for a plan.
type Plan struct {
Type PlanType `jsonapi:"attr,type"`
}
// PlanPatch is the API message for patching a plan.
type PlanPatch struct {
Type PlanType `jsonapi:"attr,type"`
}