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/03/22 13:37:29 UTC

[incubator-devlake] branch release-v0.16 updated: fix: expand Jira remotelink to LONGTEXT (#4746) (#4748)

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

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


The following commit(s) were added to refs/heads/release-v0.16 by this push:
     new f367af5ae fix: expand Jira remotelink to LONGTEXT (#4746) (#4748)
f367af5ae is described below

commit f367af5ae0cb9b9d0ce8d6d21188920fd9f9a60c
Author: mindlesscloud <li...@merico.dev>
AuthorDate: Wed Mar 22 21:37:25 2023 +0800

    fix: expand Jira remotelink to LONGTEXT (#4746) (#4748)
---
 backend/plugins/jira/models/issue_commit.go        |  2 +-
 .../20230322_expand_remotelink_url.go              | 92 ++++++++++++++++++++++
 .../jira/models/migrationscripts/register.go       |  1 +
 backend/plugins/jira/models/remotelink.go          |  2 +-
 4 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/backend/plugins/jira/models/issue_commit.go b/backend/plugins/jira/models/issue_commit.go
index 56059660f..12985acb5 100644
--- a/backend/plugins/jira/models/issue_commit.go
+++ b/backend/plugins/jira/models/issue_commit.go
@@ -26,7 +26,7 @@ type JiraIssueCommit struct {
 	ConnectionId uint64 `gorm:"primaryKey"`
 	IssueId      uint64 `gorm:"primaryKey"`
 	CommitSha    string `gorm:"primaryKey;type:varchar(40)"`
-	CommitUrl    string `gorm:"type:varchar(255)"`
+	CommitUrl    string
 }
 
 func (JiraIssueCommit) TableName() string {
diff --git a/backend/plugins/jira/models/migrationscripts/20230322_expand_remotelink_url.go b/backend/plugins/jira/models/migrationscripts/20230322_expand_remotelink_url.go
new file mode 100644
index 000000000..51a86bc34
--- /dev/null
+++ b/backend/plugins/jira/models/migrationscripts/20230322_expand_remotelink_url.go
@@ -0,0 +1,92 @@
+/*
+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 = (*expandRemotelinkUrl)(nil)
+
+type jiraRemotelink20230322 struct {
+	Url string
+}
+
+func (jiraRemotelink20230322) TableName() string {
+	return "_tool_jira_remotelinks"
+}
+
+type jiraIssueCommit20230322 struct {
+	CommitUrl string
+}
+
+func (jiraIssueCommit20230322) TableName() string {
+	return "_tool_jira_issue_commits"
+}
+
+type expandRemotelinkUrl struct{}
+
+func (script *expandRemotelinkUrl) Up(basicRes context.BasicRes) errors.Error {
+	db := basicRes.GetDal()
+	// expand _tool_jira_remotelinks.url to LONGTEXT
+	err := migrationhelper.ChangeColumnsType[jiraRemotelink20230322](
+		basicRes,
+		script,
+		jiraRemotelink20230322{}.TableName(),
+		[]string{"url"},
+		func(tmpColumnParams []interface{}) errors.Error {
+			return db.UpdateColumn(
+				&jiraRemotelink20230322{},
+				"url",
+				dal.DalClause{Expr: " ? ", Params: tmpColumnParams},
+				dal.Where("? is not null ", tmpColumnParams...),
+			)
+		},
+	)
+	if err != nil {
+		return err
+	}
+	// expand _tool_jira_issue_commits.commit_url to LONGTEXT
+	err = migrationhelper.ChangeColumnsType[jiraIssueCommit20230322](
+		basicRes,
+		script,
+		jiraIssueCommit20230322{}.TableName(),
+		[]string{"commit_url"},
+		func(tmpColumnParams []interface{}) errors.Error {
+			return db.UpdateColumn(
+				&jiraIssueCommit20230322{},
+				"commit_url",
+				dal.DalClause{Expr: " ? ", Params: tmpColumnParams},
+				dal.Where("? is not null ", tmpColumnParams...),
+			)
+		},
+	)
+	return err
+}
+
+func (*expandRemotelinkUrl) Version() uint64 {
+	return 20230322153324
+}
+
+func (*expandRemotelinkUrl) Name() string {
+	return "expand _tool_jira_remotelinks.url and _tool_jira_issue_commits.commit_url to LONGTEXT"
+}
diff --git a/backend/plugins/jira/models/migrationscripts/register.go b/backend/plugins/jira/models/migrationscripts/register.go
index 780822d40..8a69859f5 100644
--- a/backend/plugins/jira/models/migrationscripts/register.go
+++ b/backend/plugins/jira/models/migrationscripts/register.go
@@ -32,5 +32,6 @@ func All() []plugin.MigrationScript {
 		new(addJiraMultiAuth20230129),
 		new(removeIssueStdStoryPoint),
 		new(addCommitRepoPattern),
+		new(expandRemotelinkUrl),
 	}
 }
diff --git a/backend/plugins/jira/models/remotelink.go b/backend/plugins/jira/models/remotelink.go
index 5501d40d2..534b4483b 100644
--- a/backend/plugins/jira/models/remotelink.go
+++ b/backend/plugins/jira/models/remotelink.go
@@ -33,7 +33,7 @@ type JiraRemotelink struct {
 	RawJson      datatypes.JSON
 	Self         string `gorm:"type:varchar(255)"`
 	Title        string
-	Url          string `gorm:"type:varchar(255)"`
+	Url          string
 	IssueUpdated *time.Time
 }