Skip to content

Commit

Permalink
mysql support
Browse files Browse the repository at this point in the history
Signed-off-by: liuxiaomin <[email protected]>
  • Loading branch information
liuxiaomin committed Feb 21, 2021
1 parent a7be6a7 commit b930482
Show file tree
Hide file tree
Showing 9 changed files with 864 additions and 491 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ DOCKERIMAGENAME_CORE=goharbor/harbor-core
DOCKERIMAGENAME_JOBSERVICE=goharbor/harbor-jobservice
DOCKERIMAGENAME_LOG=goharbor/harbor-log
DOCKERIMAGENAME_DB=goharbor/harbor-db
DOCKERIMAGENAME_DB_MYSQL=goharbor/harbor-db-mysql
DOCKERIMAGENAME_CHART_SERVER=goharbor/chartmuseum-photon
DOCKERIMAGENAME_REGCTL=goharbor/harbor-registryctl
DOCKERIMAGENAME_EXPORTER=goharbor/harbor-exporter
Expand Down Expand Up @@ -260,6 +261,7 @@ DOCKERSAVE_PARA=$(DOCKER_IMAGE_NAME_PREPARE):$(VERSIONTAG) \
$(DOCKERIMAGENAME_CORE):$(VERSIONTAG) \
$(DOCKERIMAGENAME_LOG):$(VERSIONTAG) \
$(DOCKERIMAGENAME_DB):$(VERSIONTAG) \
$(DOCKERIMAGENAME_DB_MYSQL):$(VERSIONTAG) \
$(DOCKERIMAGENAME_JOBSERVICE):$(VERSIONTAG) \
$(DOCKERIMAGENAME_REGCTL):$(VERSIONTAG) \
$(DOCKERIMAGENAME_EXPORTER):$(VERSIONTAG) \
Expand Down Expand Up @@ -529,6 +531,11 @@ pushimage:
$(REGISTRYUSER) $(REGISTRYPASSWORD) $(REGISTRYSERVER)
@$(DOCKERRMIMAGE) $(REGISTRYSERVER)$(DOCKERIMAGENAME_DB):$(VERSIONTAG)

@$(DOCKERTAG) $(DOCKERIMAGENAME_DB_MYSQL):$(VERSIONTAG) $(REGISTRYSERVER)$(DOCKERIMAGENAME_DB_MYSQL):$(VERSIONTAG)
@$(PUSHSCRIPTPATH)/$(PUSHSCRIPTNAME) $(REGISTRYSERVER)$(DOCKERIMAGENAME_DB_MYSQL):$(VERSIONTAG) \
$(REGISTRYUSER) $(REGISTRYPASSWORD) $(REGISTRYSERVER)
@$(DOCKERRMIMAGE) $(REGISTRYSERVER)$(DOCKERIMAGENAME_DB_MYSQL):$(VERSIONTAG)

start:
@echo "loading harbor images..."
@$(DOCKERCOMPOSECMD) $(DOCKERCOMPOSE_FILE_OPT) up -d
Expand Down
3 changes: 1 addition & 2 deletions make/migrations/mysql/0004_1.8.0_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ 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.
*/
CREATE PROCEDURE PROC_UPDATE_ADMIN_JOB()
BEGIN
CREATE PROCEDURE PROC_UPDATE_ADMIN_JOB ( ) BEGIN
IF exists(select * FROM properties WHERE k = 'scan_all_policy') then
/*
In v1.7.0, it creates an record for scan all but without cron string, just update the record with the cron in properties.
Expand Down
45 changes: 26 additions & 19 deletions make/migrations/mysql/0005_1.8.2_schema.up.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
/*
Rename the duplicate names before adding "UNIQUE" constraint
*/
DO $$
BEGIN
WHILE EXISTS (SELECT count(*) FROM user_group GROUP BY group_name HAVING count(*) > 1) LOOP
UPDATE user_group AS r
SET group_name = (
/*
truncate the name if it is too long after appending the sequence number
*/
CASE WHEN (length(group_name)+length(v.seq::text)+1) > 256
THEN
substring(group_name from 1 for (255-length(v.seq::text))) || '_' || v.seq
ELSE
group_name || '_' || v.seq
END
)
FROM (SELECT id, row_number() OVER (PARTITION BY group_name ORDER BY id) AS seq FROM user_group) AS v
WHERE r.id = v.id AND v.seq > 1;
END LOOP;
END $$;
UPDATE user_group AS r
LEFT JOIN (
SELECT
id,
IF
( @gid = group_name, @idx := @idx + 1, 1 ) AS seq,
@gid := group_name AS gid
FROM
user_group,
( SELECT @idx := 0, @gid = NULL ) t
ORDER BY
group_name,
id
) v ON r.id = v.id
SET r.group_name = (
/*
truncate the name if it is too long after appending the sequence number
*/
CASE

WHEN ( length( group_name ) + length( concat( v.seq, '' ) ) + 1 ) > 256 THEN
concat( substring( group_name, 1, ( 255- length( concat( v.seq, '' ) ) ) ), '_', v.seq ) ELSE concat( group_name, '_', v.seq )
END
)
WHERE
v.seq > 1;

ALTER TABLE user_group ADD CONSTRAINT unique_group_name UNIQUE (group_name);

Expand Down
13 changes: 5 additions & 8 deletions make/migrations/mysql/0031_2.0.3_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ INSERT INTO repository (name, project_id)
repository_name NOT IN (SELECT name from repository);

/* Update the repository id of artifact records */
UPDATE artifact AS art
SET repository_id=repo.repository_id
FROM repository AS repo
UPDATE artifact AS art, repository AS repo
SET art.repository_id=repo.repository_id
WHERE art.repository_name=repo.name AND art.repository_id!=repo.repository_id;

/* Update the media type of artifact records */
UPDATE artifact AS art
UPDATE artifact AS art, `blob` AS `blob`
SET manifest_media_type=blob.content_type,
media_type=(
CASE
Expand All @@ -43,13 +42,11 @@ UPDATE artifact AS art
'application/vnd.docker.distribution.manifest.v1+prettyjws'
END
)
FROM blob AS blob
WHERE art.media_type='UNKNOWN' AND art.digest=blob.digest;

/* update tag records with negative repository id */
UPDATE tag SET
repository_id=art.repository_id
FROM artifact as art
UPDATE tag, artifact as art SET
tag.repository_id=art.repository_id
WHERE tag.artifact_id=art.id AND tag.repository_id!=art.repository_id;


Loading

0 comments on commit b930482

Please sign in to comment.