2019-02-22 08:01:16 +01:00
|
|
|
/*add robot account table*/
|
2019-01-09 02:40:17 +01:00
|
|
|
CREATE TABLE robot (
|
2019-01-07 10:26:50 +01:00
|
|
|
id SERIAL PRIMARY KEY NOT NULL,
|
|
|
|
name varchar(255),
|
|
|
|
description varchar(1024),
|
|
|
|
project_id int,
|
2019-02-23 07:13:02 +01:00
|
|
|
expiresat bigint,
|
2019-01-07 10:26:50 +01:00
|
|
|
disabled boolean DEFAULT false NOT NULL,
|
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT unique_robot UNIQUE (name, project_id)
|
|
|
|
);
|
|
|
|
|
2019-02-22 08:01:16 +01:00
|
|
|
CREATE TRIGGER robot_update_time_at_modtime BEFORE UPDATE ON robot FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
|
|
|
|
2019-03-28 05:46:35 +01:00
|
|
|
CREATE TABLE oidc_user (
|
|
|
|
id SERIAL NOT NULL,
|
|
|
|
user_id int NOT NULL,
|
2019-04-08 13:37:30 +02:00
|
|
|
/*
|
|
|
|
Encoded secret
|
|
|
|
*/
|
2019-03-28 05:46:35 +01:00
|
|
|
secret varchar(255) NOT NULL,
|
|
|
|
/*
|
|
|
|
Subject and Issuer
|
|
|
|
Subject: Subject Identifier.
|
|
|
|
Issuer: Issuer Identifier for the Issuer of the response.
|
|
|
|
The sub (subject) and iss (issuer) Claims, used together, are the only Claims that an RP can rely upon as a stable identifier for the End-User
|
|
|
|
*/
|
|
|
|
subiss varchar(255) NOT NULL,
|
2019-04-08 13:37:30 +02:00
|
|
|
/*
|
|
|
|
Encoded token
|
|
|
|
*/
|
|
|
|
token text,
|
2019-03-28 05:46:35 +01:00
|
|
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
update_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (id),
|
2019-04-08 13:37:30 +02:00
|
|
|
FOREIGN KEY (user_id) REFERENCES harbor_user(user_id),
|
2019-03-28 05:46:35 +01:00
|
|
|
UNIQUE (subiss)
|
|
|
|
);
|
|
|
|
|
2019-04-19 12:44:24 +02:00
|
|
|
CREATE TRIGGER oidc_user_update_time_at_modtime BEFORE UPDATE ON oidc_user FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
2019-03-28 05:46:35 +01:00
|
|
|
|
2019-02-22 08:01:16 +01:00
|
|
|
/*add master role*/
|
|
|
|
INSERT INTO role (role_code, name) VALUES ('DRWS', 'master');
|
|
|
|
|
|
|
|
/*delete replication jobs whose policy has been marked as "deleted"*/
|
|
|
|
DELETE FROM replication_job AS j
|
|
|
|
USING replication_policy AS p
|
|
|
|
WHERE j.policy_id = p.id AND p.deleted = TRUE;
|
|
|
|
|
|
|
|
/*delete replication policy which has been marked as "deleted"*/
|
|
|
|
DELETE FROM replication_policy AS p
|
2019-03-11 13:38:45 +01:00
|
|
|
WHERE p.deleted = TRUE;
|
|
|
|
|
2019-04-05 06:57:34 +02:00
|
|
|
/*upgrade the replication_target to registry*/
|
|
|
|
DROP TRIGGER replication_target_update_time_at_modtime ON replication_target;
|
|
|
|
ALTER TABLE replication_target RENAME TO registry;
|
|
|
|
ALTER TABLE registry ALTER COLUMN url TYPE varchar(256);
|
|
|
|
ALTER TABLE registry ADD COLUMN credential_type varchar(16);
|
|
|
|
ALTER TABLE registry RENAME COLUMN username TO access_key;
|
|
|
|
ALTER TABLE registry RENAME COLUMN password TO access_secret;
|
2019-05-07 04:47:14 +02:00
|
|
|
ALTER TABLE registry ALTER COLUMN access_secret TYPE varchar(4096);
|
2019-04-05 06:57:34 +02:00
|
|
|
ALTER TABLE registry ADD COLUMN type varchar(32);
|
|
|
|
ALTER TABLE registry DROP COLUMN target_type;
|
|
|
|
ALTER TABLE registry ADD COLUMN description text;
|
|
|
|
ALTER TABLE registry ADD COLUMN health varchar(16);
|
2019-04-08 08:33:27 +02:00
|
|
|
UPDATE registry SET type='harbor';
|
|
|
|
UPDATE registry SET credential_type='basic';
|
2019-03-11 13:38:45 +01:00
|
|
|
|
2019-04-05 06:57:34 +02:00
|
|
|
/*upgrade the replication_policy*/
|
|
|
|
ALTER TABLE replication_policy ADD COLUMN creator varchar(256);
|
|
|
|
ALTER TABLE replication_policy ADD COLUMN src_registry_id int;
|
2019-05-09 07:25:11 +02:00
|
|
|
/*A name filter "project_name/"+double star will be merged into the filters.
|
2019-04-17 10:04:54 +02:00
|
|
|
if harbor is integrated with the external project service, we cannot get the project name by ID,
|
|
|
|
which means the repilcation policy will match all resources.*/
|
2019-05-09 07:25:11 +02:00
|
|
|
UPDATE replication_policy SET filters='[]' WHERE filters='';
|
|
|
|
UPDATE replication_policy r SET filters=( r.filters::jsonb || (SELECT CONCAT('{"type":"name","value":"', p.name,'/**"}') FROM project p WHERE p.project_id=r.project_id)::jsonb);
|
2019-04-05 06:57:34 +02:00
|
|
|
ALTER TABLE replication_policy RENAME COLUMN target_id TO dest_registry_id;
|
|
|
|
ALTER TABLE replication_policy ALTER COLUMN dest_registry_id DROP NOT NULL;
|
|
|
|
ALTER TABLE replication_policy ADD COLUMN dest_namespace varchar(256);
|
|
|
|
ALTER TABLE replication_policy ADD COLUMN override boolean;
|
2019-05-09 07:25:11 +02:00
|
|
|
UPDATE replication_policy SET override=TRUE;
|
2019-04-05 06:57:34 +02:00
|
|
|
ALTER TABLE replication_policy DROP COLUMN project_id;
|
2019-04-17 10:04:54 +02:00
|
|
|
ALTER TABLE replication_policy RENAME COLUMN cron_str TO trigger;
|
2019-04-05 06:57:34 +02:00
|
|
|
|
|
|
|
DROP TRIGGER replication_immediate_trigger_update_time_at_modtime ON replication_immediate_trigger;
|
|
|
|
DROP TABLE replication_immediate_trigger;
|
2019-03-13 02:35:01 +01:00
|
|
|
|
|
|
|
create table replication_execution (
|
|
|
|
id SERIAL NOT NULL,
|
|
|
|
policy_id int NOT NULL,
|
|
|
|
status varchar(32),
|
2019-04-17 08:16:51 +02:00
|
|
|
/*the status text may contain error message whose length is very long*/
|
|
|
|
status_text text,
|
2019-03-13 02:35:01 +01:00
|
|
|
total int NOT NULL DEFAULT 0,
|
|
|
|
failed int NOT NULL DEFAULT 0,
|
|
|
|
succeed int NOT NULL DEFAULT 0,
|
|
|
|
in_progress int NOT NULL DEFAULT 0,
|
|
|
|
stopped int NOT NULL DEFAULT 0,
|
|
|
|
trigger varchar(64),
|
|
|
|
start_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
end_time timestamp NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
CREATE INDEX execution_policy ON replication_execution (policy_id);
|
|
|
|
|
|
|
|
create table replication_task (
|
|
|
|
id SERIAL NOT NULL,
|
|
|
|
execution_id int NOT NULL,
|
|
|
|
resource_type varchar(64),
|
|
|
|
src_resource varchar(256),
|
|
|
|
dst_resource varchar(256),
|
2019-04-02 07:29:17 +02:00
|
|
|
operation varchar(32),
|
2019-03-13 02:35:01 +01:00
|
|
|
job_id varchar(64),
|
|
|
|
status varchar(32),
|
|
|
|
start_time timestamp default CURRENT_TIMESTAMP,
|
|
|
|
end_time timestamp NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
2019-03-26 12:00:00 +01:00
|
|
|
CREATE INDEX task_execution ON replication_task (execution_id);
|
|
|
|
|
2019-04-05 06:57:34 +02:00
|
|
|
|
2019-04-08 08:33:27 +02:00
|
|
|
/*migrate each replication_job record to one replication_execution and one replication_task record*/
|
|
|
|
DO $$
|
|
|
|
DECLARE
|
|
|
|
job RECORD;
|
|
|
|
execid integer;
|
|
|
|
BEGIN
|
|
|
|
FOR job IN SELECT * FROM replication_job WHERE operation != 'schedule'
|
|
|
|
LOOP
|
|
|
|
/*insert one execution record*/
|
|
|
|
INSERT INTO replication_execution (policy_id, start_time) VALUES (job.policy_id, job.creation_time) RETURNING id INTO execid;
|
2019-04-17 10:04:54 +02:00
|
|
|
/*insert one task record
|
|
|
|
doesn't record the tags info in "src_resource" and "dst_resource" as the length
|
|
|
|
of the tags may longer than the capability of the column*/
|
2019-04-08 08:33:27 +02:00
|
|
|
INSERT INTO replication_task (execution_id, resource_type, src_resource, dst_resource, operation, job_id, status, start_time, end_time)
|
2019-04-17 10:04:54 +02:00
|
|
|
VALUES (execid, 'image', job.repository, job.repository, job.operation, job.job_uuid, job.status, job.creation_time, job.update_time);
|
2019-04-08 08:33:27 +02:00
|
|
|
END LOOP;
|
|
|
|
END $$;
|
|
|
|
UPDATE replication_task SET status='Pending' WHERE status='pending';
|
|
|
|
UPDATE replication_task SET status='InProgress' WHERE status='scheduled';
|
|
|
|
UPDATE replication_task SET status='InProgress' WHERE status='running';
|
|
|
|
UPDATE replication_task SET status='Failed' WHERE status='error';
|
|
|
|
UPDATE replication_task SET status='Succeed' WHERE status='finished';
|
|
|
|
UPDATE replication_task SET operation='copy' WHERE operation='transfer';
|
|
|
|
UPDATE replication_task SET operation='deletion' WHERE operation='delete';
|
|
|
|
|
|
|
|
/*upgrade the replication_job to replication_schedule_job*/
|
|
|
|
DELETE FROM replication_job WHERE operation != 'schedule';
|
|
|
|
ALTER TABLE replication_job RENAME COLUMN job_uuid TO job_id;
|
|
|
|
ALTER TABLE replication_job DROP COLUMN repository;
|
|
|
|
ALTER TABLE replication_job DROP COLUMN operation;
|
|
|
|
ALTER TABLE replication_job DROP COLUMN tags;
|
|
|
|
ALTER TABLE replication_job DROP COLUMN op_uuid;
|
|
|
|
DROP INDEX policy;
|
|
|
|
DROP INDEX poid_uptime;
|
|
|
|
DROP INDEX poid_status;
|
|
|
|
DROP TRIGGER replication_job_update_time_at_modtime ON replication_job;
|
|
|
|
ALTER TABLE replication_job RENAME TO replication_schedule_job;
|
2019-05-08 13:11:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
migrate scan all schedule
|
|
|
|
|
|
|
|
If user set the scan all schedule, move it into table admin_job, and let the api the parse the json data.
|
|
|
|
*/
|
|
|
|
DO $$
|
|
|
|
BEGIN
|
|
|
|
IF exists(select * FROM properties WHERE k = 'scan_all_policy') then
|
2019-05-10 11:08:52 +02:00
|
|
|
/*
|
|
|
|
In v1.7.0, it creates an record for scan all but without cron string, just update the record with the cron in properties.
|
|
|
|
*/
|
|
|
|
IF exists(select * FROM admin_job WHERE job_name = 'IMAGE_SCAN_ALL' AND job_kind = 'Periodic' AND deleted = 'f') then
|
|
|
|
UPDATE admin_job SET cron_str=scan_all_cron.v
|
|
|
|
FROM (select * FROM properties WHERE k = 'scan_all_policy') AS scan_all_cron
|
|
|
|
WHERE job_name = 'IMAGE_SCAN_ALL' AND job_kind = 'Periodic' AND deleted = 'f';
|
|
|
|
ELSE
|
|
|
|
INSERT INTO admin_job (job_name, job_kind, cron_str, status) VALUES ('IMAGE_SCAN_ALL', 'Periodic', (select v FROM properties WHERE k = 'scan_all_policy'), 'pending');
|
|
|
|
END IF;
|
2019-05-08 13:11:33 +02:00
|
|
|
DELETE FROM properties WHERE k='scan_all_policy';
|
|
|
|
END IF;
|
|
|
|
END $$;
|
|
|
|
|
|
|
|
|