mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-15 06:45:17 +01:00
Merge pull request #4802 from ywk253100/180427_label_db
Modify unique constraint of table harbor_label
This commit is contained in:
commit
f77e4167ac
@ -278,7 +278,7 @@ create table harbor_label (
|
||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY(id),
|
||||
CONSTRAINT unique_name_and_scope UNIQUE (name,scope)
|
||||
CONSTRAINT unique_label UNIQUE (name,scope, project_id)
|
||||
);
|
||||
|
||||
create table harbor_resource_label (
|
||||
|
@ -260,7 +260,7 @@ create table harbor_label (
|
||||
project_id int,
|
||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||
update_time timestamp default CURRENT_TIMESTAMP,
|
||||
UNIQUE(name, scope)
|
||||
UNIQUE(name, scope, project_id)
|
||||
);
|
||||
|
||||
create table harbor_resource_label (
|
||||
|
@ -25,8 +25,9 @@ import (
|
||||
)
|
||||
|
||||
func TestMethodsOfLabel(t *testing.T) {
|
||||
labelName := "test"
|
||||
label := &models.Label{
|
||||
Name: "test",
|
||||
Name: labelName,
|
||||
Level: common.LabelLevelUser,
|
||||
Scope: common.LabelScopeProject,
|
||||
ProjectID: 1,
|
||||
@ -37,6 +38,24 @@ func TestMethodsOfLabel(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
label.ID = id
|
||||
|
||||
// add a label which has the same name to another project
|
||||
projectID, err := AddProject(models.Project{
|
||||
OwnerID: 1,
|
||||
Name: "project_for_label_test",
|
||||
})
|
||||
require.Nil(t, err)
|
||||
defer GetOrmer().QueryTable(&models.Project{}).
|
||||
Filter("project_id", projectID).Delete()
|
||||
|
||||
id2, err := AddLabel(&models.Label{
|
||||
Name: labelName,
|
||||
Level: common.LabelLevelUser,
|
||||
Scope: common.LabelScopeProject,
|
||||
ProjectID: projectID,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
defer DeleteLabel(id2)
|
||||
|
||||
// get
|
||||
l, err := GetLabel(id)
|
||||
require.Nil(t, err)
|
||||
|
@ -259,7 +259,7 @@ class HarborLabel(Base):
|
||||
creation_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP"))
|
||||
update_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
|
||||
|
||||
__table_args__ = (sa.UniqueConstraint('name', 'scope', name='unique_name_and_scope'),)
|
||||
__table_args__ = (sa.UniqueConstraint('name', 'scope', 'project_id', name='unique_label'),)
|
||||
|
||||
|
||||
class HarborResourceLabel(Base):
|
||||
|
Loading…
Reference in New Issue
Block a user