You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2023/05/16 12:59:03 UTC

[incubator-devlake] branch main updated: feat: unify the length of pull_request_comments.pr_id to varchar(255) (#5209)

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

zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 42761a55d feat: unify the length of pull_request_comments.pr_id to varchar(255) (#5209)
42761a55d is described below

commit 42761a55d7db2cf7f4e608404118adb8f0a2699e
Author: abeizn <zi...@merico.dev>
AuthorDate: Tue May 16 20:58:57 2023 +0800

    feat: unify the length of pull_request_comments.pr_id to varchar(255) (#5209)
    
    * feat: unify the length of pull_request_comments.pr_id to varchar(255)
    
    * feat: unify the length of pull_request_comments.pr_id to varchar(255)
---
 .../domainlayer/code/pull_request_comment.go       |  5 +-
 .../20221109_modfiy_commits_diffs.go               |  4 +-
 ...16_change_pull_request_id_type_in_prcomments.go | 65 ++++++++++++++++++++++
 .../20230516_rename_finished_commits_diffs.go      |  2 +-
 backend/core/models/migrationscripts/register.go   |  1 +
 5 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/backend/core/models/domainlayer/code/pull_request_comment.go b/backend/core/models/domainlayer/code/pull_request_comment.go
index 048357273..05aca3460 100644
--- a/backend/core/models/domainlayer/code/pull_request_comment.go
+++ b/backend/core/models/domainlayer/code/pull_request_comment.go
@@ -18,13 +18,14 @@ limitations under the License.
 package code
 
 import (
-	"github.com/apache/incubator-devlake/core/models/domainlayer"
 	"time"
+
+	"github.com/apache/incubator-devlake/core/models/domainlayer"
 )
 
 type PullRequestComment struct {
 	domainlayer.DomainEntity
-	PullRequestId string `gorm:"index"`
+	PullRequestId string `gorm:"index;varchar(255)"`
 	Body          string
 	AccountId     string `gorm:"type:varchar(255)"`
 	CreatedDate   time.Time
diff --git a/backend/core/models/migrationscripts/20221109_modfiy_commits_diffs.go b/backend/core/models/migrationscripts/20221109_modfiy_commits_diffs.go
index 98f2d3faa..aba49d9a6 100644
--- a/backend/core/models/migrationscripts/20221109_modfiy_commits_diffs.go
+++ b/backend/core/models/migrationscripts/20221109_modfiy_commits_diffs.go
@@ -28,8 +28,8 @@ var _ plugin.MigrationScript = (*modifyCommitsDiffs)(nil)
 
 type modifyCommitsDiffs struct{}
 
-// ref_commits_diffs splits commits_diffs and _tool_refdiff_finished_commits_diffs table.
-// _tool_refdiff_finished_commits_diffs records the new_commit_sha and old_commit_sha pair that is inserted after being successfully calculated.
+// ref_commits_diffs splits commits_diffs and finished_commits_diffs table.
+// finished_commits_diffs records the new_commit_sha and old_commit_sha pair that is inserted after being successfully calculated.
 type FinishedCommitsDiffs20221109 struct {
 	NewCommitSha string `gorm:"primaryKey;type:varchar(40)"`
 	OldCommitSha string `gorm:"primaryKey;type:varchar(40)"`
diff --git a/backend/core/models/migrationscripts/20230516_change_pull_request_id_type_in_prcomments.go b/backend/core/models/migrationscripts/20230516_change_pull_request_id_type_in_prcomments.go
new file mode 100644
index 000000000..6157ec099
--- /dev/null
+++ b/backend/core/models/migrationscripts/20230516_change_pull_request_id_type_in_prcomments.go
@@ -0,0 +1,65 @@
+/*
+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/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*modifyPrLabelsAndComments)(nil)
+
+type modifyPrLabelsAndComments struct{}
+
+type pullRequestComment20230516 struct {
+	PullRequestId string `gorm:"index;type:varchar(255)"`
+}
+
+func (pullRequestComment20230516) TableName() string {
+	return "pull_request_comments"
+}
+
+func (script *modifyPrLabelsAndComments) Up(basicRes context.BasicRes) errors.Error {
+	// change pull_request_comments.pr_id to varchar(255) type
+	db := basicRes.GetDal()
+	return migrationhelper.ChangeColumnsType[pullRequestComment20230516](
+		basicRes,
+		script,
+		pullRequestComment20230516{}.TableName(),
+		[]string{"pull_request_id"},
+		func(tmpColumnParams []interface{}) errors.Error {
+			return db.UpdateColumn(
+				&pullRequestComment20230516{},
+				"pull_request_id",
+				dal.DalClause{Expr: " ? ", Params: tmpColumnParams},
+				dal.Where("? is not null", tmpColumnParams...),
+			)
+		},
+	)
+}
+
+func (*modifyPrLabelsAndComments) Version() uint64 {
+	return 20230516000001
+}
+
+func (*modifyPrLabelsAndComments) Name() string {
+	return "change pull_request_comments.pr_id to varchar(255) type"
+}
diff --git a/backend/core/models/migrationscripts/20230516_rename_finished_commits_diffs.go b/backend/core/models/migrationscripts/20230516_rename_finished_commits_diffs.go
index aca9888d4..5c672dc00 100644
--- a/backend/core/models/migrationscripts/20230516_rename_finished_commits_diffs.go
+++ b/backend/core/models/migrationscripts/20230516_rename_finished_commits_diffs.go
@@ -37,7 +37,7 @@ func (*renameFinishedCommitsDiffs) Up(basicRes context.BasicRes) errors.Error {
 }
 
 func (*renameFinishedCommitsDiffs) Version() uint64 {
-	return 20230516000001
+	return 20230516000002
 }
 
 func (*renameFinishedCommitsDiffs) Name() string {
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index 62e1498fc..ecd58feef 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -82,6 +82,7 @@ func All() []plugin.MigrationScript {
 		new(addCommitAuthoredDate),
 		new(addOriginalStatusToPullRequest20230508),
 		new(addCalendarMonths),
+		new(modifyPrLabelsAndComments),
 		new(renameFinishedCommitsDiffs),
 	}
 }