From f3260fdad1d2ddd950336449bd2475dc430d0915 Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Thu, 29 Apr 2021 12:36:08 +0800 Subject: [PATCH] move blob models (#14776) 1, move project_blob into pkg 2, move artifact_blob into pkg Signed-off-by: Wang Yan --- src/common/models/artifact_blob.go | 18 --------------- src/common/models/base.go | 2 -- src/common/models/project_blob.go | 32 -------------------------- src/pkg/blob/models/blob.go | 37 ++++++++++++++++++++++-------- 4 files changed, 28 insertions(+), 61 deletions(-) delete mode 100644 src/common/models/artifact_blob.go delete mode 100644 src/common/models/project_blob.go diff --git a/src/common/models/artifact_blob.go b/src/common/models/artifact_blob.go deleted file mode 100644 index a402306ee..000000000 --- a/src/common/models/artifact_blob.go +++ /dev/null @@ -1,18 +0,0 @@ -package models - -import ( - "time" -) - -// ArtifactAndBlob holds the relationship between manifest and blob. -type ArtifactAndBlob struct { - ID int64 `orm:"pk;auto;column(id)" json:"id"` - DigestAF string `orm:"column(digest_af)" json:"digest_af"` - DigestBlob string `orm:"column(digest_blob)" json:"digest_blob"` - CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"` -} - -// TableName ... -func (afb *ArtifactAndBlob) TableName() string { - return "artifact_blob" -} diff --git a/src/common/models/base.go b/src/common/models/base.go index ee106cdb1..988ad6b83 100644 --- a/src/common/models/base.go +++ b/src/common/models/base.go @@ -28,7 +28,5 @@ func init() { new(ResourceLabel), new(JobLog), new(OIDCUser), - new(ProjectBlob), - new(ArtifactAndBlob), ) } diff --git a/src/common/models/project_blob.go b/src/common/models/project_blob.go deleted file mode 100644 index 119dadbc0..000000000 --- a/src/common/models/project_blob.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Project Harbor Authors -// -// 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. - -package models - -import ( - "time" -) - -// ProjectBlob holds the relationship between manifest and blob. -type ProjectBlob struct { - ID int64 `orm:"pk;auto;column(id)" json:"id"` - ProjectID int64 `orm:"column(project_id)" json:"project_id"` - BlobID int64 `orm:"column(blob_id)" json:"blob_id"` - CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"` -} - -// TableName ... -func (*ProjectBlob) TableName() string { - return "project_blob" -} diff --git a/src/pkg/blob/models/blob.go b/src/pkg/blob/models/blob.go index f772dab3d..3db715074 100644 --- a/src/pkg/blob/models/blob.go +++ b/src/pkg/blob/models/blob.go @@ -21,7 +21,6 @@ import ( "github.com/docker/distribution/manifest/manifestlist" "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" - "github.com/goharbor/harbor/src/common/models" v1 "github.com/opencontainers/image-spec/specs-go/v1" "strings" "time" @@ -29,13 +28,10 @@ import ( func init() { orm.RegisterModel(&Blob{}) + orm.RegisterModel(&ArtifactAndBlob{}) + orm.RegisterModel(&ProjectBlob{}) } -// TODO: move ArtifactAndBlob, ProjectBlob to here - -// ArtifactAndBlob alias ArtifactAndBlob model -type ArtifactAndBlob = models.ArtifactAndBlob - /* the status are used for Garbage Collection StatusNone, the blob is using in Harbor as normal. @@ -69,6 +65,32 @@ var StatusMap = map[string][]string{ StatusDeleteFailed: {StatusDeleting}, } +// ArtifactAndBlob holds the relationship between manifest and blob. +type ArtifactAndBlob struct { + ID int64 `orm:"pk;auto;column(id)" json:"id"` + DigestAF string `orm:"column(digest_af)" json:"digest_af"` + DigestBlob string `orm:"column(digest_blob)" json:"digest_blob"` + CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"` +} + +// TableName ... +func (afb *ArtifactAndBlob) TableName() string { + return "artifact_blob" +} + +// ProjectBlob holds the relationship between manifest and blob. +type ProjectBlob struct { + ID int64 `orm:"pk;auto;column(id)" json:"id"` + ProjectID int64 `orm:"column(project_id)" json:"project_id"` + BlobID int64 `orm:"column(blob_id)" json:"blob_id"` + CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"` +} + +// TableName ... +func (*ProjectBlob) TableName() string { + return "project_blob" +} + // Blob holds the details of a blob. type Blob struct { ID int64 `orm:"pk;auto;column(id)" json:"id"` @@ -99,9 +121,6 @@ func (b *Blob) IsManifest() bool { b.ContentType == manifestlist.MediaTypeManifestList } -// ProjectBlob alias ProjectBlob model -type ProjectBlob = models.ProjectBlob - // FilterByArtifactDigest returns orm.QuerySeter with artifact digest filter func (b *Blob) FilterByArtifactDigest(ctx context.Context, qs orm.QuerySeter, key string, value interface{}) orm.QuerySeter { v, ok := value.(string)