Skip to content

Commit

Permalink
fix: add primary key to _tool_gitlab_assignees and _tool_gitlab_revie…
Browse files Browse the repository at this point in the history
…wers tables (#7573)
  • Loading branch information
abeizn authored and action_bot committed Jun 5, 2024
1 parent bc246b1 commit 0ab6d40
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/plugins/gitlab/models/assignee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions backend/plugins/gitlab/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ func All() []plugin.MigrationScript {
new(modifyDeploymentCommitTitle),
new(addWebUrlToGitlabPipelineProject),
new(addGitlabAssignee),
new(addGitlabAssigneeAndReviewerPrimaryKey),
}
}
2 changes: 1 addition & 1 deletion backend/plugins/gitlab/models/reviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down

0 comments on commit 0ab6d40

Please sign in to comment.