You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/06/05 02:40:50 UTC

(incubator-devlake) branch release-v0.21 updated: fix: add primary key to _tool_gitlab_assignees and _tool_gitlab_reviewers tables (#7573) (#7574)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.21
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.21 by this push:
     new d19f950db fix: add primary key to _tool_gitlab_assignees and _tool_gitlab_reviewers tables (#7573) (#7574)
d19f950db is described below

commit d19f950dbec99ec886fbeb1e63a71c92c3ce2082
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Wed Jun 5 10:40:42 2024 +0800

    fix: add primary key to _tool_gitlab_assignees and _tool_gitlab_reviewers tables (#7573) (#7574)
    
    Co-authored-by: abeizn <zi...@merico.dev>
---
 backend/plugins/gitlab/models/assignee.go          |  2 +-
 ...5_add_mr_assignees_and_reviewers_primary_key.go | 88 ++++++++++++++++++++++
 .../gitlab/models/migrationscripts/register.go     |  1 +
 backend/plugins/gitlab/models/reviewer.go          |  2 +-
 4 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/backend/plugins/gitlab/models/assignee.go b/backend/plugins/gitlab/models/assignee.go
index 85f3b377b..0fa496064 100644
--- a/backend/plugins/gitlab/models/assignee.go
+++ b/backend/plugins/gitlab/models/assignee.go
@@ -24,7 +24,7 @@ import (
 type GitlabAssignee struct {
 	ConnectionId   uint64 `gorm:"primaryKey"`
 	AssigneeId     int    `gorm:"primaryKey"`
-	MergeRequestId int    `gorm:"index"`
+	MergeRequestId int    `gorm:"primaryKey"`
 	ProjectId      int    `gorm:"index"`
 	Name           string `gorm:"type:varchar(255)"`
 	Username       string `gorm:"type:varchar(255)"`
diff --git a/backend/plugins/gitlab/models/migrationscripts/20240605_add_mr_assignees_and_reviewers_primary_key.go b/backend/plugins/gitlab/models/migrationscripts/20240605_add_mr_assignees_and_reviewers_primary_key.go
new file mode 100644
index 000000000..ef37640d2
--- /dev/null
+++ b/backend/plugins/gitlab/models/migrationscripts/20240605_add_mr_assignees_and_reviewers_primary_key.go
@@ -0,0 +1,88 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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 migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/core/context"
+	"github.com/apache/incubator-devlake/core/errors"
+	archivedCore "github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+	"github.com/apache/incubator-devlake/plugins/gitlab/models/migrationscripts/archived"
+)
+
+type addGitlabAssigneeAndReviewerPrimaryKey struct{}
+
+type GitlabAssignee20240605 struct {
+	ConnectionId   uint64 `gorm:"primaryKey"`
+	AssigneeId     int    `gorm:"primaryKey"`
+	MergeRequestId int    `gorm:"primaryKey"`
+	ProjectId      int    `gorm:"index"`
+	Name           string `gorm:"type:varchar(255)"`
+	Username       string `gorm:"type:varchar(255)"`
+	State          string `gorm:"type:varchar(255)"`
+	AvatarUrl      string `gorm:"type:varchar(255)"`
+	WebUrl         string `gorm:"type:varchar(255)"`
+	archivedCore.NoPKModel
+}
+
+func (GitlabAssignee20240605) TableName() string {
+	return "_tool_gitlab_assignees"
+}
+
+type GitlabReviewer20240605 struct {
+	ConnectionId   uint64 `gorm:"primaryKey"`
+	ReviewerId     int    `gorm:"primaryKey"`
+	MergeRequestId int    `gorm:"primaryKey"`
+	ProjectId      int    `gorm:"index"`
+	Name           string `gorm:"type:varchar(255)"`
+	Username       string `gorm:"type:varchar(255)"`
+	State          string `gorm:"type:varchar(255)"`
+	AvatarUrl      string `gorm:"type:varchar(255)"`
+	WebUrl         string `gorm:"type:varchar(255)"`
+	archivedCore.NoPKModel
+}
+
+func (GitlabReviewer20240605) TableName() string {
+	return "_tool_gitlab_reviewers"
+}
+
+func (*addGitlabAssigneeAndReviewerPrimaryKey) Up(baseRes context.BasicRes) errors.Error {
+	err := baseRes.GetDal().DropTables(archived.GitlabAssignee{}, archived.GitlabReviewer{})
+	if err != nil {
+		return err
+	}
+
+	err = migrationhelper.AutoMigrateTables(
+		baseRes,
+		&GitlabAssignee20240605{},
+		&GitlabReviewer20240605{},
+	)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func (*addGitlabAssigneeAndReviewerPrimaryKey) Version() uint64 {
+	return 20240605110339
+}
+
+func (*addGitlabAssigneeAndReviewerPrimaryKey) Name() string {
+	return "add primary key to _tool_gitlab_assignees and _tool_gitlab_reviewers tables"
+}
diff --git a/backend/plugins/gitlab/models/migrationscripts/register.go b/backend/plugins/gitlab/models/migrationscripts/register.go
index 01cd8556d..dae1eb0bc 100644
--- a/backend/plugins/gitlab/models/migrationscripts/register.go
+++ b/backend/plugins/gitlab/models/migrationscripts/register.go
@@ -47,5 +47,6 @@ func All() []plugin.MigrationScript {
 		new(addTimeToGitlabPipelineProject),
 		new(modifyDeploymentCommitTitle),
 		new(addGitlabAssignee),
+		new(addGitlabAssigneeAndReviewerPrimaryKey),
 	}
 }
diff --git a/backend/plugins/gitlab/models/reviewer.go b/backend/plugins/gitlab/models/reviewer.go
index 8bffc2f54..3acef38af 100644
--- a/backend/plugins/gitlab/models/reviewer.go
+++ b/backend/plugins/gitlab/models/reviewer.go
@@ -24,7 +24,7 @@ import (
 type GitlabReviewer struct {
 	ConnectionId   uint64 `gorm:"primaryKey"`
 	ReviewerId     int    `gorm:"primaryKey"`
-	MergeRequestId int    `gorm:"index"`
+	MergeRequestId int    `gorm:"primaryKey"`
 	ProjectId      int    `gorm:"index"`
 	Name           string `gorm:"type:varchar(255)"`
 	Username       string `gorm:"type:varchar(255)"`