forked from horizoncd/horizon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20210908_initial_schema.sql
313 lines (299 loc) · 16.4 KB
/
20210908_initial_schema.sql
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
-- Copyright © 2023 Horizoncd.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- group table
CREATE TABLE `group`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '',
`path` varchar(32) NOT NULL DEFAULT '',
`description` varchar(256) DEFAULT NULL,
`visibility_level` varchar(16) NOT NULL COMMENT 'public or private',
`parent_id` bigint(20) NOT NULL DEFAULT 0 COMMENT 'ID of the parent group',
`traversal_ids` varchar(32) NOT NULL DEFAULT '' COMMENT 'ID path from the root, like 1,2,3',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_parent_id_name_delete_at` (`parent_id`, `name`, `deleted_at`),
UNIQUE KEY `idx_parent_id_path_delete_at` (`parent_id`, `path`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- user table
CREATE TABLE `user`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL DEFAULT '',
`full_name` varchar(128) DEFAULT '',
`email` varchar(64) NOT NULL DEFAULT '',
`phone` varchar(32) DEFAULT NULL COMMENT '',
`oidc_id` varchar(64) NOT NULL COMMENT 'oidc id, which is a unique key in oidc system.',
`oidc_type` varchar(64) NOT NULL COMMENT 'oidc type, such as google, github, gitlab etc.',
`admin` tinyint(1) NOT NULL COMMENT 'is system admin,0-false,1-true',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_name` (`name`),
UNIQUE KEY `idx_email`(`email`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- template table
CREATE TABLE `template`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'the name of template',
`description` varchar(256) NULL COMMENT 'the template description',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_name` (`name`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- template release table
CREATE TABLE `template_release`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`template_name` varchar(64) NOT NULL COMMENT 'the name of template',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'the name of template release',
`description` varchar(256) NOT NULL COMMENT 'description about this template release',
`gitlab_project` varchar(256) NOT NULL COMMENT 'project ID or relative path in gitlab',
`recommended` tinyint(1) NOT NULL COMMENT 'is the most recommended template, 0-false, 1-true',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_template_name_name` (`template_name`, `name`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- member table
CREATE TABLE `member`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`resource_type` varchar(64) NOT NULL COMMENT 'group\application\cluster',
`resource_id` bigint(20) unsigned NOT NULL COMMENT 'resource id',
`role` varchar(64) NOT NULL COMMENT 'binding role name',
`member_type` tinyint(1) COMMENT '0-USER, 1-group',
`membername_id` bigint(20) unsigned NOT NULL COMMENT 'UserID or GroupID',
`granted_by` bigint(20) unsigned NOT NULL COMMENT 'who grant the role',
`created_by` bigint(20) unsigned NOT NULL COMMENT 'who create the role',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_resource_member` (`resource_type`, `resource_id`, `member_type`, `membername_id`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- application table
CREATE TABLE `application`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`group_id` bigint(20) unsigned NOT NULL COMMENT 'group id',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'the name of application',
`description` varchar(256) DEFAULT NULL COMMENT 'the description of application',
`priority` varchar(16) NOT NULL DEFAULT 'P3' COMMENT 'the priority of application',
`git_url` varchar(128) DEFAULT NULL COMMENT 'git repo url',
`git_subfolder` varchar(128) DEFAULT NULL COMMENT 'git repo subfolder',
`git_branch` varchar(128) DEFAULT NULL COMMENT 'git default branch',
`template` varchar(64) NOT NULL COMMENT 'template name',
`template_release` varchar(64) NOT NULL COMMENT 'template release',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_name_deleted_at` (`name`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- k8s cluster table
CREATE TABLE `k8s_cluster`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'k8s name',
`server` varchar(256) NOT NULL DEFAULT '' COMMENT 'k8s server',
`certificate` text NOT NULL COMMENT 'k8s certificate',
`ingress_domain` varchar(128) DEFAULT NULL COMMENT 'k8s ingress address',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_server`(`server`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- harbor table
CREATE TABLE `harbor`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`server` varchar(256) NOT NULL DEFAULT '' COMMENT 'harbor server address',
`token` varchar(512) NOT NULL COMMENT 'harbor server token',
`preheat_policy_id` int(2) COMMENT 'p2p preheat policy id',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- environment table
CREATE TABLE `environment`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'env name',
`display_name` varchar(128) NOT NULL DEFAULT '' COMMENT 'display name',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_name` (`name`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- region table
CREATE TABLE `region`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'region name',
`display_name` varchar(128) NOT NULL DEFAULT '' COMMENT 'region display name',
`k8s_cluster_id` bigint(20) unsigned NOT NULL COMMENT 'k8s cluster id',
`harbor_id` bigint(20) unsigned NOT NULL COMMENT 'harbor id',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_name` (`name`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- environment_region table
CREATE TABLE `environment_region`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`environment_name` varchar(128) NOT NULL DEFAULT '' COMMENT 'environment name',
`region_name` varchar(128) NOT NULL DEFAULT '' COMMENT 'region name',
`disabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is disabled,0-false,1-true',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
UNIQUE KEY `idx_env_region` (`environment_name`, `region_name`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- cluster table
CREATE TABLE `cluster`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`application_id` bigint(20) unsigned NOT NULL COMMENT 'application id',
`name` varchar(64) NOT NULL DEFAULT '' COMMENT 'the name of cluster',
`description` varchar(256) DEFAULT NULL COMMENT 'the description of cluster',
`git_url` varchar(128) DEFAULT NULL COMMENT 'git repo url',
`git_subfolder` varchar(128) DEFAULT NULL COMMENT 'git repo subfolder',
`git_branch` varchar(128) DEFAULT NULL COMMENT 'git branch',
`template` varchar(64) NOT NULL COMMENT 'template name',
`template_release` varchar(64) NOT NULL COMMENT 'template release',
`environment_region_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'env',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_deleted_at` (`deleted_at`),
KEY `idx_application_id` (`application_id`),
UNIQUE KEY `idx_name_deleted_at` (`name`, `deleted_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- cluster tag table
CREATE TABLE `cluster_tag`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cluster_id` bigint(20) unsigned NOT NULL COMMENT 'cluster id',
`tag_key` varchar(64) NOT NULL DEFAULT '' COMMENT 'key of tag',
`tag_value` varchar(1280) NOT NULL DEFAULT '' COMMENT 'value of tag',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
`updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater',
PRIMARY KEY (`id`),
KEY `idx_cluster_id` (`cluster_id`),
KEY `idx_key` (`tag_key`),
UNIQUE KEY `idx_cluster_id_key` (`cluster_id`, `tag_key`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;
-- pipelinerun table
CREATE TABLE `pipelinerun`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cluster_id` bigint(20) unsigned NOT NULL COMMENT 'cluster id',
`action` varchar(64) NOT NULL COMMENT 'action',
`status` varchar(64) NOT NULL DEFAULT '' COMMENT 'the pipelinerun status',
`title` varchar(256) NOT NULL DEFAULT '' COMMENT 'the title of pipelinerun',
`description` varchar(2048) DEFAULT NULL COMMENT 'the description of pipelinerun',
`git_url` varchar(128) DEFAULT NULL COMMENT 'git repo url',
`git_branch` varchar(128) DEFAULT NULL COMMENT 'the branch to build of this pipelinerun',
`git_commit` varchar(128) DEFAULT NULL COMMENT 'the commit to build of this pipelinerun',
`image_url` varchar(256) DEFAULT NULL COMMENT 'image url',
`last_config_commit` varchar(128) DEFAULT NULL COMMENT 'the last commit of cluster config',
`config_commit` varchar(128) DEFAULT NULL COMMENT 'the new commit of cluster config',
`s3_bucket` varchar(128) NOT NULL DEFAULT '' COMMENT 's3 bucket to storage this pipelinerun log',
`log_object` varchar(258) NOT NULL DEFAULT '' COMMENT 's3 object for log',
`pr_object` varchar(258) NOT NULL DEFAULT '' COMMENT 's3 object for pipelinerun',
`started_at` datetime DEFAULT NULL COMMENT 'start time of this pipelinerun',
`finished_at` datetime DEFAULT NULL COMMENT 'finish time of this pipelinerun',
`rollback_from` bigint(20) unsigned NULL COMMENT 'the pipelinerun id that this pipelinerun rollback from',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator',
PRIMARY KEY (`id`),
KEY `idx_cluster_action` (`cluster_id`, `action`),
KEY `idx_cluster_config_commit` (`cluster_id`, `config_commit`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8mb4;