mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-11 21:48:03 +02:00
Merge pull request #7310 from ywk253100/190404_test
Upgrade the registry and replication policy tables
This commit is contained in:
commit
bfc41addb0
@ -44,42 +44,36 @@ WHERE j.policy_id = p.id AND p.deleted = TRUE;
|
|||||||
DELETE FROM replication_policy AS p
|
DELETE FROM replication_policy AS p
|
||||||
WHERE p.deleted = TRUE;
|
WHERE p.deleted = TRUE;
|
||||||
|
|
||||||
CREATE TABLE registry (
|
/*upgrade the replication_target to registry*/
|
||||||
id SERIAL PRIMARY KEY NOT NULL,
|
DROP TRIGGER replication_target_update_time_at_modtime ON replication_target;
|
||||||
name varchar(256),
|
ALTER TABLE replication_target RENAME TO registry;
|
||||||
url varchar(256),
|
ALTER TABLE registry ALTER COLUMN url TYPE varchar(256);
|
||||||
credential_type varchar(16),
|
ALTER TABLE registry ADD COLUMN credential_type varchar(16);
|
||||||
access_key varchar(128),
|
UPDATE registry SET credential_type='basic' WHERE credential_type='';
|
||||||
access_secret varchar(1024),
|
ALTER TABLE registry RENAME COLUMN username TO access_key;
|
||||||
type varchar(32),
|
ALTER TABLE registry RENAME COLUMN password TO access_secret;
|
||||||
insecure boolean,
|
ALTER TABLE registry ALTER COLUMN access_secret TYPE varchar(1024);
|
||||||
description varchar(1024),
|
ALTER TABLE registry ADD COLUMN type varchar(32);
|
||||||
health varchar(16),
|
UPDATE registry SET type='harbor' WHERE type='';
|
||||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
ALTER TABLE registry DROP COLUMN target_type;
|
||||||
update_time timestamp default CURRENT_TIMESTAMP,
|
ALTER TABLE registry ADD COLUMN description text;
|
||||||
CONSTRAINT unique_registry_name UNIQUE (name)
|
ALTER TABLE registry ADD COLUMN health varchar(16);
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE "replication_policy_ng" (
|
/*upgrade the replication_policy*/
|
||||||
"id" SERIAL PRIMARY KEY NOT NULL,
|
ALTER TABLE replication_policy ADD COLUMN creator varchar(256);
|
||||||
"name" varchar(256),
|
ALTER TABLE replication_policy ADD COLUMN src_registry_id int;
|
||||||
"description" text,
|
ALTER TABLE replication_policy ADD COLUMN src_namespaces varchar(256);
|
||||||
"creator" varchar(256),
|
/*if harbor is integrated with the external project service, the src_namespaces will be empty,
|
||||||
"src_registry_id" int4,
|
which means the repilcation policy cannot work as expected*/
|
||||||
"src_namespaces" varchar(256),
|
UPDATE replication_policy r SET src_namespaces=(SELECT p.name FROM project p WHERE p.project_id=r.project_id);
|
||||||
"dest_registry_id" int4,
|
ALTER TABLE replication_policy RENAME COLUMN target_id TO dest_registry_id;
|
||||||
"dest_namespace" varchar(256),
|
ALTER TABLE replication_policy ALTER COLUMN dest_registry_id DROP NOT NULL;
|
||||||
"override" bool NOT NULL DEFAULT false,
|
ALTER TABLE replication_policy ADD COLUMN dest_namespace varchar(256);
|
||||||
"enabled" bool NOT NULL DEFAULT true,
|
ALTER TABLE replication_policy ADD COLUMN override boolean;
|
||||||
"cron_str" varchar(256),
|
ALTER TABLE replication_policy DROP COLUMN project_id;
|
||||||
"filters" varchar(1024),
|
|
||||||
"replicate_deletion" bool NOT NULL DEFAULT false,
|
DROP TRIGGER replication_immediate_trigger_update_time_at_modtime ON replication_immediate_trigger;
|
||||||
"start_time" timestamp(6),
|
DROP TABLE replication_immediate_trigger;
|
||||||
"deleted" bool NOT NULL DEFAULT false,
|
|
||||||
"creation_time" timestamp(6) DEFAULT now(),
|
|
||||||
"update_time" timestamp(6) DEFAULT now(),
|
|
||||||
CONSTRAINT unique_policy_ng_name UNIQUE ("name")
|
|
||||||
);
|
|
||||||
|
|
||||||
create table replication_execution (
|
create table replication_execution (
|
||||||
id SERIAL NOT NULL,
|
id SERIAL NOT NULL,
|
||||||
@ -122,4 +116,12 @@ create table replication_schedule_job (
|
|||||||
update_time timestamp NULL,
|
update_time timestamp NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
CREATE INDEX replication_schedule_job_index ON replication_schedule_job (policy_id);
|
CREATE INDEX replication_schedule_job_index ON replication_schedule_job (policy_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
* consider how to handle the replication_job;
|
||||||
|
* the replication_job contains schedule job;
|
||||||
|
* the schedule job has been removed from jobservice, how to handle this?
|
||||||
|
* keep consistent with the webhook handler?
|
||||||
|
*/
|
@ -112,7 +112,7 @@ func cleanByUser(username string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
err = execUpdate(o, `delete from replication_target where id < 99`)
|
err = execUpdate(o, `delete from registry where id < 99`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func testForAll(m *testing.M) int {
|
|||||||
func clearAll() {
|
func clearAll() {
|
||||||
tables := []string{"project_member",
|
tables := []string{"project_member",
|
||||||
"project_metadata", "access_log", "repository", "replication_policy",
|
"project_metadata", "access_log", "repository", "replication_policy",
|
||||||
"replication_target", "replication_job", "replication_immediate_trigger", "img_scan_job",
|
"registry", "replication_job", "img_scan_job",
|
||||||
"img_scan_overview", "clair_vuln_timestamp", "project", "harbor_user"}
|
"img_scan_overview", "clair_vuln_timestamp", "project", "harbor_user"}
|
||||||
for _, t := range tables {
|
for _, t := range tables {
|
||||||
if err := ClearTable(t); err != nil {
|
if err := ClearTable(t); err != nil {
|
||||||
|
@ -21,7 +21,7 @@ type RepPolicy struct {
|
|||||||
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
|
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName set table name for ORM. TODO: replace _ng suffix.
|
// TableName set table name for ORM.
|
||||||
func (r *RepPolicy) TableName() string {
|
func (r *RepPolicy) TableName() string {
|
||||||
return "replication_policy_ng"
|
return "replication_policy"
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,10 @@ func convertFromPersistModel(policy *persist_models.RepPolicy) (*model.Policy, e
|
|||||||
ply.SrcNamespaces = strings.Split(policy.SrcNamespaces, ",")
|
ply.SrcNamespaces = strings.Split(policy.SrcNamespaces, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO need to consider the consistence with the policies from previous versions
|
||||||
|
// of Harbor
|
||||||
|
// both for filter and trigger
|
||||||
|
|
||||||
// 2. parse Filters
|
// 2. parse Filters
|
||||||
if len(policy.Filters) > 0 {
|
if len(policy.Filters) > 0 {
|
||||||
filters := []*model.Filter{}
|
filters := []*model.Filter{}
|
||||||
|
Loading…
Reference in New Issue
Block a user