2016-02-01 12:59:10 +01:00
|
|
|
drop database if exists registry;
|
|
|
|
create database registry charset = utf8;
|
|
|
|
|
|
|
|
use registry;
|
|
|
|
|
|
|
|
create table access (
|
|
|
|
access_id int NOT NULL AUTO_INCREMENT,
|
|
|
|
access_code char(1),
|
|
|
|
comment varchar (30),
|
|
|
|
primary key (access_id)
|
|
|
|
);
|
|
|
|
|
2016-03-25 10:42:58 +01:00
|
|
|
insert into access (access_code, comment) values
|
|
|
|
('M', 'Management access for project'),
|
|
|
|
('R', 'Read access for project'),
|
|
|
|
('W', 'Write access for project'),
|
|
|
|
('D', 'Delete access for project'),
|
|
|
|
('S', 'Search access for project');
|
2016-02-01 12:59:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
create table role (
|
|
|
|
role_id int NOT NULL AUTO_INCREMENT,
|
2016-03-25 09:58:20 +01:00
|
|
|
role_mask int DEFAULT 0 NOT NULL,
|
2016-02-01 12:59:10 +01:00
|
|
|
role_code varchar(20),
|
|
|
|
name varchar (20),
|
|
|
|
primary key (role_id)
|
|
|
|
);
|
2016-03-25 09:58:20 +01:00
|
|
|
/*
|
|
|
|
role mask is used for future enhancement when a project member can have multi-roles
|
|
|
|
currently set to 0
|
|
|
|
*/
|
2016-02-01 12:59:10 +01:00
|
|
|
|
2016-03-25 10:42:58 +01:00
|
|
|
insert into role (role_code, name) values
|
|
|
|
('MDRWS', 'projectAdmin'),
|
|
|
|
('RWS', 'developer'),
|
|
|
|
('RS', 'guest');
|
2016-02-01 12:59:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
create table user (
|
|
|
|
user_id int NOT NULL AUTO_INCREMENT,
|
2016-08-19 08:59:46 +02:00
|
|
|
# The max length of username controlled by API is 20,
|
|
|
|
# and 11 is reserved for marking the deleted users.
|
|
|
|
# The mark of deleted user is "#user_id".
|
|
|
|
# The 11 consist of 10 for the max value of user_id(4294967295)
|
|
|
|
# in MySQL and 1 of '#'.
|
2017-08-17 07:09:33 +02:00
|
|
|
username varchar(255),
|
2016-08-19 08:59:46 +02:00
|
|
|
# 11 bytes is reserved for marking the deleted users.
|
|
|
|
email varchar(255),
|
2016-02-01 12:59:10 +01:00
|
|
|
password varchar(40) NOT NULL,
|
2017-06-19 18:19:30 +02:00
|
|
|
realname varchar (255) NOT NULL,
|
2016-02-01 12:59:10 +01:00
|
|
|
comment varchar (30),
|
|
|
|
deleted tinyint (1) DEFAULT 0 NOT NULL,
|
|
|
|
reset_uuid varchar(40) DEFAULT NULL,
|
|
|
|
salt varchar(40) DEFAULT NULL,
|
2016-03-25 09:58:20 +01:00
|
|
|
sysadmin_flag tinyint (1),
|
|
|
|
creation_time timestamp,
|
|
|
|
update_time timestamp,
|
2016-02-01 12:59:10 +01:00
|
|
|
primary key (user_id),
|
|
|
|
UNIQUE (username),
|
|
|
|
UNIQUE (email)
|
|
|
|
);
|
|
|
|
|
2016-03-25 10:42:58 +01:00
|
|
|
insert into user (username, email, password, realname, comment, deleted, sysadmin_flag, creation_time, update_time) values
|
|
|
|
('admin', 'admin@example.com', '', 'system admin', 'admin user',0, 1, NOW(), NOW()),
|
|
|
|
('anonymous', 'anonymous@example.com', '', 'anonymous user', 'anonymous user', 1, 0, NOW(), NOW());
|
2016-02-01 12:59:10 +01:00
|
|
|
|
|
|
|
create table project (
|
|
|
|
project_id int NOT NULL AUTO_INCREMENT,
|
|
|
|
owner_id int NOT NULL,
|
2016-08-23 09:56:30 +02:00
|
|
|
# The max length of name controlled by API is 30,
|
2016-09-02 05:24:06 +02:00
|
|
|
# and 11 is reserved for marking the deleted project.
|
2016-08-23 09:56:30 +02:00
|
|
|
name varchar (41) NOT NULL,
|
2016-02-01 12:59:10 +01:00
|
|
|
creation_time timestamp,
|
2016-03-25 09:58:20 +01:00
|
|
|
update_time timestamp,
|
2016-02-01 12:59:10 +01:00
|
|
|
deleted tinyint (1) DEFAULT 0 NOT NULL,
|
|
|
|
primary key (project_id),
|
2016-02-17 07:29:05 +01:00
|
|
|
FOREIGN KEY (owner_id) REFERENCES user(user_id),
|
|
|
|
UNIQUE (name)
|
2016-02-01 12:59:10 +01:00
|
|
|
);
|
|
|
|
|
2017-09-29 10:37:43 +02:00
|
|
|
insert into project (owner_id, name, creation_time, update_time) values
|
|
|
|
(1, 'library', NOW(), NOW());
|
2016-02-01 12:59:10 +01:00
|
|
|
|
2016-03-25 09:58:20 +01:00
|
|
|
create table project_member (
|
2016-02-01 12:59:10 +01:00
|
|
|
project_id int NOT NULL,
|
|
|
|
user_id int NOT NULL,
|
2016-03-25 09:58:20 +01:00
|
|
|
role int NOT NULL,
|
|
|
|
creation_time timestamp,
|
|
|
|
update_time timestamp,
|
|
|
|
PRIMARY KEY (project_id, user_id),
|
|
|
|
FOREIGN KEY (role) REFERENCES role(role_id),
|
|
|
|
FOREIGN KEY (project_id) REFERENCES project(project_id),
|
|
|
|
FOREIGN KEY (user_id) REFERENCES user(user_id)
|
|
|
|
);
|
2016-02-01 12:59:10 +01:00
|
|
|
|
2016-03-25 10:42:58 +01:00
|
|
|
insert into project_member (project_id, user_id, role, creation_time, update_time) values
|
2016-03-25 09:58:20 +01:00
|
|
|
(1, 1, 1, NOW(), NOW());
|
2016-02-01 12:59:10 +01:00
|
|
|
|
2017-09-28 07:52:53 +02:00
|
|
|
create table project_metadata (
|
2017-10-30 10:03:28 +01:00
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
2017-09-28 07:52:53 +02:00
|
|
|
project_id int NOT NULL,
|
|
|
|
name varchar(255) NOT NULL,
|
|
|
|
value varchar(255),
|
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
|
|
deleted tinyint (1) DEFAULT 0 NOT NULL,
|
2017-10-30 10:03:28 +01:00
|
|
|
PRIMARY KEY (id),
|
|
|
|
CONSTRAINT unique_project_id_and_name UNIQUE (project_id,name),
|
2017-09-28 07:52:53 +02:00
|
|
|
FOREIGN KEY (project_id) REFERENCES project(project_id)
|
|
|
|
);
|
|
|
|
|
2017-10-30 10:03:28 +01:00
|
|
|
insert into project_metadata (id, project_id, name, value, creation_time, update_time, deleted) values
|
|
|
|
(1, 1, 'public', 'true', NOW(), NOW(), 0);
|
2017-09-28 07:52:53 +02:00
|
|
|
|
2016-02-01 12:59:10 +01:00
|
|
|
create table access_log (
|
|
|
|
log_id int NOT NULL AUTO_INCREMENT,
|
2017-08-17 07:09:33 +02:00
|
|
|
username varchar (255) NOT NULL,
|
2016-02-01 12:59:10 +01:00
|
|
|
project_id int NOT NULL,
|
2016-06-22 06:22:02 +02:00
|
|
|
repo_name varchar (256),
|
|
|
|
repo_tag varchar (128),
|
2016-02-01 12:59:10 +01:00
|
|
|
GUID varchar(64),
|
|
|
|
operation varchar(20) NOT NULL,
|
|
|
|
op_time timestamp,
|
|
|
|
primary key (log_id),
|
2017-05-10 12:28:19 +02:00
|
|
|
INDEX pid_optime (project_id, op_time)
|
2016-02-01 12:59:10 +01:00
|
|
|
);
|
2016-04-07 10:49:11 +02:00
|
|
|
|
2016-08-29 15:21:49 +02:00
|
|
|
create table repository (
|
|
|
|
repository_id int NOT NULL AUTO_INCREMENT,
|
|
|
|
name varchar(255) NOT NULL,
|
|
|
|
project_id int NOT NULL,
|
|
|
|
description text,
|
|
|
|
pull_count int DEFAULT 0 NOT NULL,
|
|
|
|
star_count int DEFAULT 0 NOT NULL,
|
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
|
|
primary key (repository_id),
|
|
|
|
UNIQUE (name)
|
|
|
|
);
|
|
|
|
|
2016-05-10 13:38:50 +02:00
|
|
|
create table replication_policy (
|
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
|
|
|
name varchar(256),
|
|
|
|
project_id int NOT NULL,
|
|
|
|
target_id int NOT NULL,
|
2016-04-20 08:24:17 +02:00
|
|
|
enabled tinyint(1) NOT NULL DEFAULT 1,
|
2016-05-10 13:38:50 +02:00
|
|
|
description text,
|
2016-08-11 08:02:53 +02:00
|
|
|
deleted tinyint (1) DEFAULT 0 NOT NULL,
|
2016-04-20 08:24:17 +02:00
|
|
|
cron_str varchar(256),
|
2016-06-01 07:28:02 +02:00
|
|
|
start_time timestamp NULL,
|
2016-05-10 13:38:50 +02:00
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
create table replication_target (
|
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
|
|
|
name varchar(64),
|
|
|
|
url varchar(64),
|
2017-08-17 07:09:33 +02:00
|
|
|
username varchar(255),
|
2016-08-03 11:25:24 +02:00
|
|
|
password varchar(128),
|
2016-06-17 12:54:29 +02:00
|
|
|
/*
|
|
|
|
target_type indicates the type of target registry,
|
|
|
|
0 means it's a harbor instance,
|
|
|
|
1 means it's a regulart registry
|
|
|
|
*/
|
|
|
|
target_type tinyint(1) NOT NULL DEFAULT 0,
|
2017-09-22 09:08:10 +02:00
|
|
|
insecure tinyint(1) NOT NULL DEFAULT 0,
|
2016-05-10 13:38:50 +02:00
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
create table replication_job (
|
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
|
|
|
status varchar(64) NOT NULL,
|
|
|
|
policy_id int NOT NULL,
|
|
|
|
repository varchar(256) NOT NULL,
|
|
|
|
operation varchar(64) NOT NULL,
|
2016-05-25 10:33:45 +02:00
|
|
|
tags varchar(16384),
|
2016-05-10 13:38:50 +02:00
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
2016-07-07 13:05:47 +02:00
|
|
|
PRIMARY KEY (id),
|
2016-09-02 12:34:35 +02:00
|
|
|
INDEX policy (policy_id),
|
|
|
|
INDEX poid_uptime (policy_id, update_time)
|
2016-05-10 13:38:50 +02:00
|
|
|
);
|
2016-04-20 08:24:17 +02:00
|
|
|
|
2017-05-11 15:41:57 +02:00
|
|
|
create table img_scan_job (
|
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
|
|
|
status varchar(64) NOT NULL,
|
|
|
|
repository varchar(256) NOT NULL,
|
|
|
|
tag varchar(128) NOT NULL,
|
2017-06-08 09:04:23 +02:00
|
|
|
digest varchar(128),
|
2017-05-11 15:41:57 +02:00
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2017-06-13 15:46:52 +02:00
|
|
|
create table img_scan_overview (
|
2017-07-09 06:37:08 +02:00
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
2017-06-13 15:46:52 +02:00
|
|
|
image_digest varchar(128) NOT NULL,
|
|
|
|
scan_job_id int NOT NULL,
|
|
|
|
/* 0 indicates none, the higher the number, the more severe the status */
|
|
|
|
severity int NOT NULL default 0,
|
|
|
|
/* the json string to store components severity status, currently use a json to be more flexible and avoid creating additional tables. */
|
|
|
|
components_overview varchar(2048),
|
|
|
|
/* primary key for querying details, in clair it should be the name of the "top layer" */
|
|
|
|
details_key varchar(128),
|
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
2017-07-09 06:37:08 +02:00
|
|
|
PRIMARY KEY(id),
|
|
|
|
UNIQUE(image_digest)
|
2017-06-13 15:46:52 +02:00
|
|
|
);
|
|
|
|
|
2017-07-04 06:12:16 +02:00
|
|
|
create table clair_vuln_timestamp (
|
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
|
|
|
namespace varchar(128) NOT NULL,
|
|
|
|
last_update timestamp NOT NULL,
|
|
|
|
PRIMARY KEY(id),
|
|
|
|
UNIQUE(namespace)
|
|
|
|
);
|
|
|
|
|
2016-04-07 10:49:11 +02:00
|
|
|
create table properties (
|
2017-11-15 07:49:14 +01:00
|
|
|
id int NOT NULL AUTO_INCREMENT,
|
2016-04-07 10:49:11 +02:00
|
|
|
k varchar(64) NOT NULL,
|
|
|
|
v varchar(128) NOT NULL,
|
2017-11-15 07:49:14 +01:00
|
|
|
PRIMARY KEY(id),
|
|
|
|
UNIQUE (k)
|
2016-04-07 10:49:11 +02:00
|
|
|
);
|
|
|
|
|
2016-05-09 08:11:34 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS `alembic_version` (
|
|
|
|
`version_num` varchar(32) NOT NULL
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
|
2017-11-02 10:00:51 +01:00
|
|
|
insert into alembic_version values ('1.3.0');
|